home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1994 November / Cd Ware (Nro. 2) - Epimundo.iso / OS2 / FILEB185.ZIP / SOURCE / FILEBAR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-09  |  237.5 KB  |  5,111 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. //                                FileBar
  4. //
  5. //         OS/2 Application Launch Facility and WPS Shell Replacement
  6. //
  7. //                         Written By Eric A. Wolf
  8. //                 Copyright (C) 1994 - All Rights Reserved
  9. //
  10. // This source code may be used for reference ONLY!  It is provided AS-IS and no
  11. // guarantees are made as to its utility, functionality or correctness.  It is
  12. // provided solely as a guide to aid aspiring OS/2 2.x Presentation Manager
  13. // programmers in developing their own PM applications.  No modifications are
  14. // to be made to this code for re-release as a same or different product.  This
  15. // code must be distributed (in its original entirety) with the executable
  16. // portion of this product.
  17. //
  18. //          -- Please register this shareware product for $10 today --
  19. //                          See documentation for details
  20. //
  21. // Project Start Date:      December 26, 1993
  22. // Project Completion Date: January   3, 1994
  23. //
  24. // Written using Borland C++ for OS/2, version 1.0, Borland Resource Workshop,
  25. //               and the IBM OS/2 2.1 bitmap/icon editor
  26. //
  27. // File Last Modified:      May       9, 1994
  28. //
  29. ////////////////////////////////////////////////////////////////////////////////
  30.  
  31.  
  32. ////////////////////////////////////////////////////////////////////////////////
  33. // set compile-time flags for what os/2 header information should be included
  34. ////////////////////////////////////////////////////////////////////////////////
  35. #define INCL_PM
  36. #define INCL_DOSSESMGR
  37. #define INCL_DOSERRORS
  38. #define INCL_DOSMISC
  39. #define INCL_WINPOINTERS
  40. #define INCL_WINPROGRAMLIST
  41. #define INCL_WINSTDFILE
  42. #define INCL_WINWORKPLACE
  43. #define INCL_DOSPROCESS
  44.  
  45.  
  46. ////////////////////////////////////////////////////////////////////////////////
  47. // include C, C++, OS/2, application and resource header files
  48. ////////////////////////////////////////////////////////////////////////////////
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include <ctype.h>
  52. #include <string.h>
  53. #include <time.h>
  54. #include "filebar.h"
  55. #include "dll/filebar.h"                      // include DLL function prototypes
  56.  
  57.  
  58. ////////////////////////////////////////////////////////////////////////////////
  59. // MakeHourglassPointer - macro to make the mouse pointer the hourglass
  60. ////////////////////////////////////////////////////////////////////////////////
  61. #define MakeHourglassPointer() {                                                               \
  62.                                  HPOINTER pointer;                                             \
  63.                                  pointer = WinQuerySysPointer( HWND_DESKTOP, SPTR_WAIT, FALSE);\
  64.                                  WinSetPointer( HWND_DESKTOP, pointer );                       \
  65.                                }
  66.  
  67.  
  68. ////////////////////////////////////////////////////////////////////////////////
  69. // MakeArrowPointer - macro to make the mouse pointer the arrow
  70. ////////////////////////////////////////////////////////////////////////////////
  71. #define MakeArrowPointer() {                                                                \
  72.                              HPOINTER pointer;                                              \
  73.                              pointer = WinQuerySysPointer( HWND_DESKTOP, SPTR_ARROW, FALSE);\
  74.                              WinSetPointer( HWND_DESKTOP, pointer );                        \
  75.                            }
  76.  
  77.  
  78. ////////////////////////////////////////////////////////////////////////////////
  79. // define application constants
  80. ////////////////////////////////////////////////////////////////////////////////
  81. #define EXTERN
  82. #define MAXCOUNT              200
  83. #define TEMPSTRING            64
  84. #define AT_TOP                TRUE
  85. #define AT_BOTTOM             FALSE
  86. #define TIMERID               1
  87. #define MAXTASKS              30
  88. #define MAXMENUS              7
  89. #define MAXITEMS              32
  90. #define MAXPATH               CCHMAXPATH
  91. #define MAXACTIONSTRINGLENGTH MAXPATH
  92. #define MAXITEMNAMELENGTH     24
  93. #define MAXMENUNAMELENGTH     20
  94. #define MAXARGSTRINGLENGTH    64
  95. #define MAXDIRSTRINGLENGTH    MAXPATH
  96. #define WINDOWED              1
  97. #define FULLSCREEN            2
  98. #define PM                    4
  99. #define DOS                   8
  100. #define OS2                   16
  101. #define WINOS2                32
  102. #define STARTMIN              64
  103. #define STARTMAX              128
  104. #define WPSFOLDER             256
  105. #define STARTASWPS            512
  106. #define SCALED                128
  107. #define TILED                 64
  108. #define OS2SHELL              "CMD.EXE"
  109. #define OPTIONFILE            "FILEBAR.INI"
  110. #define LAUNCHFILE            "STARTPRG.CMD"
  111. #define LAUNCHINPUTS          "/C STARTPRG.CMD"
  112. #define SEPARATOR             "────────────────────────"
  113. #define WPSDESKTOPNAME        "Desktop"
  114. #define FILEBARMENUON         "~FileBar"
  115. #define FILEBARMENUOFF        "\x04"
  116. #define TASKMENUON            "~Task List"
  117. #define TASKMENUOFF           "~Tasks"
  118. #define STARTINPUT            '['
  119. #define ENDINPUT              ']'
  120. #define BITMAPNAME            "\\FILEBAR.BMP\0"
  121. #define CHIMESOUNDFILE        "\\CHIME.WAV\0"
  122. #define NOCOLOR               1
  123. #define MAXSTARTITEMS         10
  124. #define WPSBUFFER             3084
  125. #define MAXALARMS             32
  126. #define SCHEDULE_EVERYHOUR    1
  127. #define SCHEDULE_EVERYDAY     2
  128. #define SCHEDULE_EVERYWEEK    4
  129. #define SCHEDULE_EVERYMONTH   8
  130. #define SCHEDULE_EVERYYEAR    16
  131. #define SCHEDULE_USEWAVFILE   32
  132. #define SCHEDULE_SOUNDONLY    64
  133. #define SCHEDULE_LAUNCHAPP    128
  134. #define BOOLEAN               INT
  135. #define LAUNCHED              0
  136. #define TERMCHAR              250
  137.  
  138.  
  139. ////////////////////////////////////////////////////////////////////////////////
  140. // writeString - writes a string out with quotes on either side
  141. ////////////////////////////////////////////////////////////////////////////////
  142. #define writeString(stream, string) fprintf(stream, "%c%s%c\n", TERMCHAR, string, TERMCHAR)
  143.  
  144.  
  145. ////////////////////////////////////////////////////////////////////////////////
  146. // define function prototypes
  147. ////////////////////////////////////////////////////////////////////////////////
  148. VOID validateTimeEntry( VOID );
  149. VOID sortTimeEntries( INT );
  150. VOID displayBackground( VOID );
  151. VOID resizeMenu( VOID );
  152. VOID readOptionFile( VOID );
  153. VOID writeOptionFile( VOID );
  154. VOID readString( FILE*, CHAR* );
  155. VOID restartTimer( VOID );
  156. VOID displayTimeDate( VOID );
  157. VOID SwapTwoMenus( SHORT, SHORT );
  158. VOID SwapTwoItems( SHORT, SHORT, SHORT );
  159. VOID updateItemList( HWND );
  160. VOID updateEditItemData( HWND hWnd );
  161. VOID updateEditItemData( HWND hWnd );
  162. VOID ExecuteStartUpList( VOID );
  163. VOID updateCalendar( HWND );
  164. VOID ringChime( CHAR* );
  165. VOID checkAlarms( SHORT, SHORT, SHORT, SHORT, SHORT );
  166. VOID updateTimeDisplay( HWND );
  167. VOID reviseScheduledItem( INT );
  168. VOID resetFileDialog( VOID );
  169. BYTE numberOfDaysInMonth( INT, INT );
  170. SHORT startApplication( SHORT, SHORT );
  171. MRESULT EXPENTRY ClientWndProc( HWND, ULONG, MPARAM, MPARAM );
  172. MRESULT EXPENTRY GenericProc( HWND, ULONG, MPARAM, MPARAM );
  173. MRESULT EXPENTRY TimeDateProc( HWND, ULONG, MPARAM, MPARAM );
  174. MRESULT EXPENTRY EditMenuProc( HWND, ULONG, MPARAM, MPARAM );
  175. MRESULT EXPENTRY AddAMenuProc( HWND, ULONG, MPARAM, MPARAM );
  176. MRESULT EXPENTRY EditItemProc( HWND, ULONG, MPARAM, MPARAM );
  177. MRESULT EXPENTRY EditItemDataProc( HWND, ULONG, MPARAM, MPARAM );
  178. MRESULT EXPENTRY AddAnItemProc( HWND, ULONG, MPARAM, MPARAM );
  179. MRESULT EXPENTRY menuHandler( HWND, ULONG, MPARAM, MPARAM );
  180. MRESULT EXPENTRY EnterParamProc( HWND, ULONG, MPARAM, MPARAM );
  181. MRESULT EXPENTRY backgroundProc( HWND, ULONG, MPARAM, MPARAM );
  182. MRESULT EXPENTRY startupProc( HWND, ULONG, MPARAM, MPARAM );
  183. MRESULT EXPENTRY schedulerProc( HWND, ULONG, MPARAM, MPARAM );
  184. MRESULT EXPENTRY scheduleProc( HWND, ULONG, MPARAM, MPARAM );
  185. MRESULT EXPENTRY reminderNoteProc( HWND, ULONG, MPARAM, MPARAM );
  186. MRESULT EXPENTRY itemProc( HWND, ULONG, MPARAM, MPARAM );
  187. MRESULT EXPENTRY showAllItemsProc( HWND, ULONG, MPARAM, MPARAM );
  188. MRESULT EXPENTRY LaunchItemProc( HWND, ULONG, MPARAM, MPARAM );
  189. MRESULT EXPENTRY popUpOptionsProc( HWND, ULONG, MPARAM, MPARAM );
  190.  
  191. extern "C" {
  192.     #define INCL_REXXSAA
  193.     #include "rexxsaa.h"
  194.     RexxStart rexxStart;
  195.     }
  196.  
  197.  
  198. ////////////////////////////////////////////////////////////////////////////////
  199. // define alarm/task scheduler item structure
  200. ////////////////////////////////////////////////////////////////////////////////
  201. struct ALARMS {
  202.     BYTE  AlarmYear;
  203.     BYTE  AlarmMonth;
  204.     BYTE  AlarmDay;
  205.     BYTE  AlarmHour;
  206.     BYTE  AlarmMinute;
  207.     BYTE  options;
  208.     CHAR  ReminderWAV[MAXACTIONSTRINGLENGTH];
  209.     CHAR  ActionToDo[MAXACTIONSTRINGLENGTH];
  210. };
  211.  
  212.  
  213. ////////////////////////////////////////////////////////////////////////////////
  214. // define menu item structure
  215. ////////////////////////////////////////////////////////////////////////////////
  216. struct USERMENUITEM {
  217.     CHAR     ItemName[MAXITEMNAMELENGTH];
  218.     CHAR     ActionToDo[MAXACTIONSTRINGLENGTH];
  219.     CHAR     Directory[MAXDIRSTRINGLENGTH];
  220.     CHAR     CmdLnArgs[MAXARGSTRINGLENGTH];
  221.     SHORT    ProgType;
  222. };
  223.  
  224.  
  225. ////////////////////////////////////////////////////////////////////////////////
  226. // define global variables
  227. ////////////////////////////////////////////////////////////////////////////////
  228. const    BYTE daysInMonth[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
  229. USERMENUITEM* Menus[MAXMENUS][MAXITEMS];
  230. ALARMS* alarmPtr[MAXALARMS];
  231. HAB      hab;
  232. HMQ      hmq;
  233. PID      TaskId[MAXTASKS];
  234. PFNWP    menuMessageHandler;
  235. FILEDLG  fileDlgInfo;
  236. MENUITEM menuData[MAXMENUS];
  237. LONG     oldNumItems;
  238. LONG     ScreenSizeX   = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN) + 2;
  239. LONG     ScreenSizeY   = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  240. LONG     MenuHeight    = WinQuerySysValue(HWND_DESKTOP, SV_CYMENU) + 2;
  241. LONG     sysMenuHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYMENU) + 2;
  242. ULONG    popUpMessageID = WM_CHORD;
  243. ULONG    noteTimerNumber;
  244. ULONG    timerNumber;
  245. ULONG    timeOption = TIMEANDDATE;
  246. USHORT   year;
  247. SHORT    startDay;
  248. SHORT    ItemSelection;
  249. SHORT    MenuSelection;
  250. SHORT    oldProgType;
  251. HWND     hwndClient;
  252. HWND     hwndFrame;
  253. HWND     hwndMenu;
  254. HWND     TaskHandle[MAXTASKS];
  255. HWND     popUpMenu = 0;
  256. HWND     oldTaskHandles[MAXTASKS];
  257. //CHAR*    settingsPath = 0;
  258. CHAR     stringTerminator = '\0';
  259. CHAR     MenuName[MAXMENUS][MAXMENUNAMELENGTH];
  260. CHAR     backgroundBitmap[MAXACTIONSTRINGLENGTH];
  261. CHAR     hourlyChimeWavFile[MAXACTIONSTRINGLENGTH];
  262. CHAR     variableText[MAXARGSTRINGLENGTH-2];
  263. CHAR     oldItemName[MAXITEMNAMELENGTH];
  264. CHAR     oldDirectory[MAXACTIONSTRINGLENGTH];
  265. CHAR     oldAction[MAXACTIONSTRINGLENGTH];
  266. CHAR     oldCmdLn[MAXARGSTRINGLENGTH];
  267. CHAR     parameterTitle[MAXITEMNAMELENGTH];
  268. CHAR     tmpBuffer[MAXPATH];
  269. INT      backgroundAttr = 3 + TILED;
  270. INT      numAlarms = 0;
  271. INT      numberOfAlarms;
  272. INT      repeatTime = 60;
  273. INT      EditItem;
  274. INT      NumMenus;
  275. INT      taskItemSelected;
  276. INT      numStartItems = 0;
  277. INT      StartUpMenu[MAXSTARTITEMS];
  278. INT      StartUpItem[MAXSTARTITEMS];
  279. INT      day;
  280. INT      month;
  281. PCHAR    ParameterTextPtr;
  282. PCHAR    currentReminderWavFile;
  283. BOOLEAN  alreadyChimed = FALSE;
  284. BOOLEAN  BarPosition = AT_TOP;
  285. BOOLEAN  HourlyChime = TRUE;
  286. BOOLEAN  FileBarMenuOn = TRUE;
  287. BOOLEAN  timeSync;
  288. BOOLEAN  checkBeforeDelete = TRUE;
  289. BOOLEAN  showBackground = FALSE;
  290. BOOLEAN  isBackgroundDisplayed = FALSE;
  291. BOOLEAN  startUp = TRUE;
  292. BOOLEAN  DoStartUpList = FALSE;
  293. BOOLEAN  allowPopUpMenu = TRUE;
  294. BOOLEAN  maximizeDesktop = FALSE;
  295. BOOLEAN  interceptMsg = TRUE;
  296. BOOLEAN  hideFileBar = FALSE;
  297. BYTE     NumItems[MAXMENUS];
  298. BOOL     FileBarIsShell = FALSE;
  299.  
  300.  
  301. ////////////////////////////////////////////////////////////////////////////////
  302. // main function - application entry point
  303. ////////////////////////////////////////////////////////////////////////////////
  304. main( int argc, char* argv[] )
  305. {
  306.     struct tm *time_now;
  307.     ULONG FrameFlags;
  308.     time_t currentTime;
  309.     hab = WinInitialize(0);                   // handle: anchor block
  310.     hmq = WinCreateMsgQueue(hab, 0);          // handle: message queue
  311.     CHAR ClassName[] = "FileBar";             // store a name for our class
  312.     MENUITEM menuItem;                        // used to modify menu data
  313.  
  314.     //--------------------------------------------------------------------------
  315.     // register the window class
  316.     //--------------------------------------------------------------------------
  317.     WinRegisterClass(hab,
  318.                      ClassName,      // name of class being registered
  319.                      ClientWndProc,  // window procedure for class
  320.                      0,              // class style
  321.                      0);             // extra memory to reserve
  322.  
  323.     //--------------------------------------------------------------------------
  324.     // create a window with a menu bar added on.  Note that the menu bar could
  325.     // be defined in the WinCreateStdWindow call (set the resource id equal= to
  326.     // MENUBAR) but is not since I need a handle to the menu (so I can later
  327.     // modify the menu).  Thus, WinLoadMenu is used following WinCreateStdWindow
  328.     //--------------------------------------------------------------------------
  329.     FrameFlags = FCF_AUTOICON|FCF_TASKLIST|FCF_BORDER|FCF_MENU;
  330.     hwndFrame = WinCreateStdWindow(HWND_DESKTOP,       // parent
  331.                                         WS_VISIBLE,    // style
  332.                                         &FrameFlags,   // control data
  333.                                         ClassName,     // client name
  334.                                         ClassName,     // title bar text
  335.                                         0,             // client style
  336.                                         NULLHANDLE,    // resource handle
  337.                                         MENUBAR,       // resource id
  338.                                         &hwndClient);  // client pointer
  339.  
  340.     //--------------------------------------------------------------------------
  341.     // move and size application to span entire top of desktop
  342.     //--------------------------------------------------------------------------
  343.     WinSetWindowPos( hwndFrame, (HWND)0, 0, (ScreenSizeY-MenuHeight),
  344.                      ScreenSizeX, MenuHeight, SWP_MOVE|SWP_SIZE|SWP_MINIMIZE);
  345.     WinEnableWindowUpdate( hwndFrame, FALSE);
  346.  
  347.     hwndMenu = WinWindowFromID( hwndFrame, FID_MENU );
  348.     MakeHourglassPointer ();                  // switch to hourglass cursor
  349.                                               // during initialization
  350.  
  351.     //--------------------------------------------------------------------------
  352.     // perform basic initialization
  353.     //--------------------------------------------------------------------------
  354.     NumMenus = 0;
  355.     MenuSelection = 100;
  356.  
  357.     for ( short k = 0; k < MAXMENUS; k++ ) {
  358.         WinSendMsg( hwndMenu, MM_QUERYITEM, MPFROM2SHORT(100*(k+1),TRUE),MPFROMP(&menuData[k]));
  359.         menuItem = menuData[k];
  360.         menuItem.afStyle = MIS_STATIC;
  361.         menuItem.afAttribute = MIA_DISABLED;
  362.         menuItem.hwndSubMenu = (HWND)0;
  363.         WinSendMsg( hwndMenu, MM_SETITEM, MPFROM2SHORT(100*(k+1),TRUE),MPFROMP(&menuItem));
  364.         WinSetMenuItemText( hwndMenu, 100*(k+1), "");
  365.         NumItems[ k ] = 0;
  366.         }
  367.  
  368.     memset( &fileDlgInfo, 0, sizeof(FILEDLG));
  369.     fileDlgInfo.cbSize = sizeof(fileDlgInfo);
  370.     menuMessageHandler = WinSubclassWindow( hwndMenu, menuHandler );
  371.  
  372.  
  373.     //--------------------------------------------------------------------------
  374.     // decide if FileBar is replacement shell or not
  375.     //--------------------------------------------------------------------------
  376.     {
  377.         PSZ buffer;
  378.  
  379.         k=0;
  380.         DosScanEnv( "RUNWORKPLACE", &buffer);
  381.         while (buffer[k]!=0) {
  382.             if ((buffer[k]=='F') || (buffer[k]=='f'))
  383.                 if (strnicmp(&buffer[k],"filebar",7)==0) {
  384.                     FileBarIsShell = TRUE;
  385.                     WinRemoveSwitchEntry( WinQuerySwitchHandle( hwndFrame, 0 ) );
  386.                     }
  387.             k++;
  388.             }
  389.     }
  390.  
  391.  
  392.     //--------------------------------------------------------------------------
  393.     // change to directory that application executable is started from
  394.     //--------------------------------------------------------------------------
  395.     if (argc > 0) {
  396.         strncpy( tmpBuffer, argv[0], sizeof(tmpBuffer) );
  397.         if (tmpBuffer[1]==':')
  398.             DosSetDefaultDisk( (ULONG)(toupper(tmpBuffer[0])-'A' + 1) );
  399.  
  400.         k = strlen(tmpBuffer);
  401.         while ((tmpBuffer[k]!='\\') && (k>0))
  402.            k--;
  403.  
  404.         if (k) {
  405.             tmpBuffer[k]='\0';
  406.             if (DosSetCurrentDir( tmpBuffer )!=0) {
  407.                 char mesg[]="Could not switch to the directory holding the application";
  408.                 WinMessageBox( HWND_DESKTOP, hwndFrame, mesg, tmpBuffer, 0,
  409.                                MB_MOVEABLE|MB_ERROR|MB_OK);
  410.                 }
  411.             }
  412.         strcpy( backgroundBitmap, tmpBuffer );
  413.         strcat( backgroundBitmap, BITMAPNAME );
  414.         strcpy( hourlyChimeWavFile, tmpBuffer );
  415.         strcat( hourlyChimeWavFile, CHIMESOUNDFILE );
  416.         }
  417.  
  418.  
  419.     //--------------------------------------------------------------------------
  420.     // if user has passed us a second argument, it is path to settings file
  421.     //--------------------------------------------------------------------------
  422.     //if (argc > 1) {
  423.     //    settingsPath = new CHAR[MAXPATH];
  424.     //    strncpy( settingsPath, argv[1], MAXPATH );
  425.     //}
  426.  
  427.  
  428.     //--------------------------------------------------------------------------
  429.     // record time and date for scheduler program
  430.     //--------------------------------------------------------------------------
  431.     tzset();
  432.     time(¤tTime);
  433.     time_now = localtime( ¤tTime );
  434.     month = time_now->tm_mon;
  435.     year = time_now->tm_year;
  436.  
  437.  
  438.     //--------------------------------------------------------------------------
  439.     // read in the user option file and set up the menu bar appropriately
  440.     // check the user time/date option and put it on the menu bar
  441.     // reset our timer in case they want the current time displayed
  442.     //--------------------------------------------------------------------------
  443.     readOptionFile();                         // read in option file
  444.     sortTimeEntries( numAlarms );             // sort the alarm entries
  445.     restartTimer();                           // resync our clock
  446.     updateTimeDisplay( hwndMenu );            // display current date/time
  447.  
  448.     // make FileBar visible
  449.     WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0, SWP_RESTORE);
  450.  
  451.     if ((maximizeDesktop) && (BarPosition==AT_TOP)) {
  452.         ULONG numItems;
  453.         ULONG Buffer;
  454.         PSWBLOCK SwitchBlockPtr;
  455.  
  456.         // get the # of items and the switch list from the system
  457.         numItems = WinQuerySwitchList( hab, NULL, 0 );
  458.         Buffer = (numItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
  459.         PVOID my = new BYTE[Buffer];
  460.         WinQuerySwitchList( hab, (SWBLOCK*)my, Buffer );
  461.         SwitchBlockPtr = (PSWBLOCK)(my);
  462.  
  463.         for (k = 0; k < numItems; k++ )
  464.             if (strcmp(SwitchBlockPtr->aswentry[k].swctl.szSwtitle, WPSDESKTOPNAME) == 0) {
  465.                 WinSetWindowPos( SwitchBlockPtr->aswentry[k].swctl.hwnd,
  466.                                  (HWND)0, 0, 0, 0, 0, SWP_MAXIMIZE);
  467.                 WinSetWindowPos( SwitchBlockPtr->aswentry[k].swctl.hwnd,
  468.                                  (HWND)0, 0, 0, ScreenSizeX,
  469.                                  ScreenSizeY-MenuHeight+sysMenuHeight+1, SWP_MOVE|SWP_SIZE);
  470.                 }
  471.         }
  472.  
  473.     displayBackground();                      // restore user background bitmap
  474.     ExecuteStartUpList();                     // start execution list
  475.     MakeArrowPointer ();                      // switch back to arrow pointer,
  476.     WinSetParent( hwndFrame, HWND_DESKTOP, FALSE );
  477.     WinSetFocus( HWND_DESKTOP, hwndFrame );
  478.  
  479.  
  480.     //--------------------------------------------------------------------------
  481.     // initialize our DLL so that we intercept window sizing messages and hide
  482.     // the bar if we need to do so
  483.     //--------------------------------------------------------------------------
  484.     FileBarInit( hwndFrame );
  485.     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  486.                       allowPopUpMenu, popUpMessageID );
  487.     if (hideFileBar)
  488.         WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0, SWP_HIDE);
  489.  
  490.     WinEnableWindowUpdate( hwndFrame, TRUE);
  491.     WinInvalidateRegion( hwndFrame, NULL, FALSE );
  492.  
  493.  
  494.     //--------------------------------------------------------------------------
  495.     // create a message queue and then as long as there are messages to get,
  496.     // get them and dispatch them to our message handlers
  497.     //--------------------------------------------------------------------------
  498.     {
  499.         QMSG qmsg;                                     // create a message queue
  500.  
  501.         while( WinGetMsg( hab, &qmsg, (HWND)0, 0, 0 ) !=FALSE )
  502.             WinDispatchMsg( hab, &qmsg );
  503.     }
  504.  
  505.  
  506.     //--------------------------------------------------------------------------
  507.     // our application is done.  Destroy timer, window, the message queue and
  508.     // release the DLL.  Call the system to destroy anchor block and do the
  509.     // final clean up work
  510.     //--------------------------------------------------------------------------
  511.     if (timerNumber != 0)
  512.         WinStopTimer( hab, hwndFrame, timerNumber );
  513.     FileBarQuit();                                // release the DLL from memory
  514.     WinDestroyWindow(hwndFrame);
  515.     WinDestroyMsgQueue(hmq);
  516.     WinTerminate(hab);
  517.     return 0;
  518. }
  519.  
  520.  
  521. ////////////////////////////////////////////////////////////////////////////////
  522. // a new font has been selected for our menu, resize and redraw the menubar
  523. ////////////////////////////////////////////////////////////////////////////////
  524. VOID resizeMenu()
  525. {
  526.     HPS hps;
  527.     FONTMETRICS fm;
  528.  
  529.     hps = WinGetPS( hwndMenu );
  530.     GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fm);
  531.     MenuHeight = fm.lLowerCaseDescent + fm.lMaxAscender + 4;
  532.     if (MenuHeight < (fm.lLowerCaseDescent + fm.lLowerCaseAscent + 2))
  533.         MenuHeight = fm.lLowerCaseDescent + fm.lLowerCaseAscent + 2;
  534.     if (MenuHeight < (WinQuerySysValue(HWND_DESKTOP, SV_CYMENU) + 2))
  535.         MenuHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYMENU) + 2;
  536.     WinReleasePS( hps );
  537.  
  538.     if (BarPosition==AT_BOTTOM)
  539.         WinSetWindowPos( hwndFrame, (HWND)0, 0, -1,
  540.                          ScreenSizeX, MenuHeight, SWP_MOVE|SWP_SIZE);
  541.     else
  542.         WinSetWindowPos( hwndFrame, (HWND)0, 0, (ScreenSizeY-MenuHeight)+1,
  543.                          ScreenSizeX, MenuHeight, SWP_MOVE|SWP_SIZE);
  544.     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  545.                       allowPopUpMenu, popUpMessageID );
  546. }
  547.  
  548.  
  549. ////////////////////////////////////////////////////////////////////////////////
  550. // subclassed menu handler for main application window
  551. ////////////////////////////////////////////////////////////////////////////////
  552. MRESULT EXPENTRY menuHandler(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  553. {
  554.     switch (msg) {
  555.         //----------------------------------------------------------------------
  556.         // if a menu has been highlighted, save which one it is so that we know
  557.         // which task to affect if something is chosen off cascading menu
  558.         //----------------------------------------------------------------------
  559.         case WM_MENUSELECT:
  560.         {
  561.             if ((SHORT1FROMMP(mp1)>TASKLIST_MENU) && (SHORT1FROMMP(mp1)<99))
  562.                 taskItemSelected = SHORT1FROMMP(mp1);
  563.             return menuMessageHandler(hwnd, msg, mp1, mp2);
  564.         }
  565.         //----------------------------------------------------------------------
  566.         // resize menubar if a font was just dropped on us
  567.         //----------------------------------------------------------------------
  568.         case WM_PRESPARAMCHANGED:
  569.         {
  570.             if ( (ULONG)mp1 == PP_FONTNAMESIZE)
  571.                 resizeMenu();
  572.             return menuMessageHandler(hwnd, msg, mp1, mp2);
  573.         }
  574.         //----------------------------------------------------------------------
  575.         // nothing of interest, pass it onto the system for default processing
  576.         //----------------------------------------------------------------------
  577.         default:
  578.             break;
  579.         }
  580.     return menuMessageHandler(hwnd, msg, mp1, mp2);
  581. }
  582.  
  583.  
  584. //////////////////////////////////////////////////////////////////////////////
  585. // This is the message processing facility for the main application thread
  586. ////////////////////////////////////////////////////////////////////////////////
  587. MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  588. {
  589.     switch (msg) {
  590.         //----------------------------------------------------------------------
  591.         // if the application is terminating, write user settings to a file
  592.         //----------------------------------------------------------------------
  593.         case WM_CLOSE:
  594.         case WM_SAVEAPPLICATION:
  595.         case WM_QUIT: {
  596.             writeOptionFile();
  597.             return WinDefWindowProc(hwnd, msg, mp1, mp2);  // default processing
  598.             }
  599.         //----------------------------------------------------------------------
  600.         // the application has been designed such that a WM_TIMER is sent by the
  601.         // system every minute (so that we can update our time on the menubar
  602.         // if necessary)
  603.         //----------------------------------------------------------------------
  604.         case WM_TIMER: {
  605.             if (!timeSync) {
  606.                 WinStopTimer( hab, hwndClient, timerNumber );
  607.                 timerNumber = WinStartTimer( hab, hwndClient, TIMERID, 60000);
  608.                 timeSync = TRUE;
  609.                 }
  610.             displayTimeDate();
  611.             return WinDefWindowProc(hwnd, msg, mp1, mp2);  // default processing
  612.             }
  613.         //----------------------------------------------------------------------
  614.         // a WM_INITMENU message is sent just prior to any pulldown menu being
  615.         // displayed.  This gives us a chance to change its contents before it
  616.         // is displayed.  If necessary, we update menu contents for user menus
  617.         //----------------------------------------------------------------------
  618.         case WM_INITMENU: {
  619.             SHORT menuId = SHORT1FROMMP(mp1);
  620.             //------------------------------------------------------------------
  621.             // if the FileBar menu is being readied for display, make sure the
  622.             // move-bar top/bottom item and check items read appropriately!
  623.             //------------------------------------------------------------------
  624.             if (menuId == FILEBAR_MENU) {
  625.                 HWND window = HWNDFROMMP( mp2 );
  626.  
  627.                 if (BarPosition == AT_TOP )
  628.                     WinSetMenuItemText( window, FILEBAR_MOVEBAR, "~Move to Bottom");
  629.                 else
  630.                     WinSetMenuItemText( window, FILEBAR_MOVEBAR, "~Move to Top");
  631.  
  632.                 WinCheckMenuItem( window, FILEBAR_STARTUP, DoStartUpList);
  633.                 WinCheckMenuItem( window, FILEBAR_DISPLAYBACKGROUND, showBackground);
  634.                 WinCheckMenuItem( window, FILEBAR_FILEBARMENU, (TRUE - FileBarMenuOn));
  635.                 WinCheckMenuItem( window, FILEBAR_CONFIRMCLOSE, checkBeforeDelete);
  636.                 WinCheckMenuItem( window, FILEBAR_RESIZEWPS, maximizeDesktop);
  637.                 WinCheckMenuItem( window, FILEBAR_INTERCEPTMSG, interceptMsg );
  638.  
  639.                 if (!FileBarIsShell)
  640.                     WinEnableMenuItem( window, FILEBAR_RESIZEWPS, (BarPosition==AT_TOP));
  641.                 else {
  642.                     WinSendMsg( window, MM_DELETEITEM, MPFROM2SHORT( FILEBAR_EXIT, TRUE ), 0 );
  643.                     WinEnableMenuItem( window, FILEBAR_RESIZEWPS, FALSE);
  644.                     }
  645.                 return WinDefWindowProc(hwnd, msg, mp1, mp2);  // default processing
  646.                 }
  647.             //------------------------------------------------------------------
  648.             // if the user is pulling down the task list, put a current copy of
  649.             // the task list in the menu and store copies of all the tasks id
  650.             // numbers and handles just in case they want to jump to one of them
  651.             //------------------------------------------------------------------
  652.             if (menuId == TASKLIST_MENU) {
  653.                 SHORT i,j;
  654.                 PCHAR text;
  655.                 MENUITEM menuItem;
  656.                 USHORT index;
  657.                 ULONG numItems;
  658.                 ULONG Buffer;
  659.                 SWCNTRL tmp;
  660.                 PVOID my;
  661.  
  662.                 // clear out the menu, get it ready for new task entries
  663.                 for (i = menuId+1; i <= menuId+MAXITEMS; i++ )
  664.                     WinSendMsg( HWNDFROMMP( mp2 ), MM_DELETEITEM,
  665.                                 MPFROM2SHORT( i, TRUE ), 0 );
  666.  
  667.                 // get the # of items and the switch list from the system
  668.                 numItems = WinQuerySwitchList( hab, NULL, 0 );
  669.                 Buffer = (numItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
  670.                 my = new BYTE[Buffer];
  671.                 WinQuerySwitchList( hab, (SWBLOCK*)my, Buffer );
  672.  
  673.                 // insert each task as an entry under the task list menu
  674.                 menuItem.iPosition = 0;
  675.                 menuItem.afStyle = MIS_MULTMENU|MIS_SINGLE;
  676.                 menuItem.afAttribute = 0;
  677.                 menuItem.id = TASKLIST_MENU;
  678.  
  679.                 for (j = 0; j < numItems; j++ ) {
  680.                     tmp = ((PSWBLOCK)(my))->aswentry[j].swctl;
  681.                     menuItem.id++;
  682.                     if ((tmp.uchVisibility != SWL_GRAYED) &&
  683.                         (tmp.uchVisibility != SWL_INVISIBLE) &&
  684.                         (tmp.hwnd != hwndFrame)) {
  685.  
  686.                         // load in the cascading menu for this task entry
  687.                         menuItem.hwndSubMenu = WinLoadMenu(hwndMenu, 0, TASKMENUCLOSE);
  688.  
  689.                         // remove ctrl characters from task list
  690.                         index = 0;
  691.                         text = tmp.szSwtitle;
  692.                         while (text[++index]!='\0')
  693.                             if (text[index]<' ')
  694.                                 text[index]=' ';
  695.  
  696.                         // enter task into the menu structure
  697.                         WinSendMsg( HWNDFROMMP(mp2), MM_INSERTITEM,
  698.                                    (MENUITEM*)&menuItem,
  699.                                   &(tmp.szSwtitle) );
  700.  
  701.                         TaskId[j] = tmp.idProcess;
  702.                         TaskHandle[j] = tmp.hwnd;
  703.                         WinSetWindowBits(menuItem.hwndSubMenu, QWL_STYLE, MS_CONDITIONALCASCADE, MS_CONDITIONALCASCADE);
  704.                         WinSendMsg(menuItem.hwndSubMenu, MM_SETDEFAULTITEMID, MPFROMSHORT(TASK_SWITCHTO), NULL);
  705.                         }
  706.                     }
  707.                 delete( my );
  708.                 return WinDefWindowProc(hwnd, msg, mp1, mp2);  // default processing
  709.                 }
  710.             //------------------------------------------------------------------
  711.             // one of the user menus is being initialized; if it has been marked
  712.             // as needing to be updated, fill the menu with the current items
  713.             // the user has set up
  714.             //------------------------------------------------------------------
  715.             if (menuId >= 100) {
  716.                 int MenuToUpdate = menuId / 100 - 1;
  717.                 MENUITEM menuItem;
  718.                 SHORT i,j;
  719.  
  720.                 for (i = menuId+1; i < menuId+MAXITEMS+1; i++ )
  721.                     WinSendMsg( HWNDFROMMP( mp2 ), MM_DELETEITEM,
  722.                                 MPFROM2SHORT( i, TRUE ), 0 );
  723.                 menuItem.iPosition = MIT_END;
  724.                 menuItem.afStyle = MIS_TEXT;
  725.                 menuItem.afAttribute = 0;
  726.                 menuItem.hItem = 0;
  727.                 menuItem.hwndSubMenu = (HWND)0;
  728.                 menuItem.id = menuId;
  729.                 for (j = 0; j < NumItems[ MenuToUpdate ]; j++ ) {
  730.                     menuItem.id++;
  731.                     if (Menus[MenuToUpdate][j]->ItemName[0] != '\0')
  732.                         WinSendMsg( HWNDFROMMP(mp2), MM_INSERTITEM,
  733.                                     (MENUITEM*)&menuItem,
  734.                                     Menus[MenuToUpdate][j]->ItemName );
  735.                     else {
  736.                         menuItem.afStyle = MIS_SEPARATOR;
  737.                         WinSendMsg( HWNDFROMMP(mp2), MM_INSERTITEM,
  738.                                     (MENUITEM*)&menuItem,
  739.                                     0 );
  740.                         menuItem.afStyle = MIS_TEXT;
  741.                         }
  742.                     }
  743.                 }
  744.             }
  745.         //----------------------------------------------------------------------
  746.         // process all WM_COMMAND messages below:
  747.         //----------------------------------------------------------------------
  748.         case WM_COMMAND: {
  749.             USHORT command = SHORT1FROMMP(mp1);
  750.             //------------------------------------------------------------------
  751.             // it was not a user item, process now as usual
  752.             //------------------------------------------------------------------
  753.             switch( command ) {
  754.                 //--------------------------------------------------------------
  755.                 // user has invoked popup menu
  756.                 //--------------------------------------------------------------
  757.                 case POPUPMENU: {
  758.                     POINTL pointData;
  759.                     SHORT i;
  760.  
  761.                     if (popUpMenu)
  762.                         WinDestroyWindow( popUpMenu );
  763.  
  764.                     popUpMenu = WinLoadMenu( HWND_DESKTOP, NULLHANDLE, MENUBAR );
  765.  
  766.                     for (i=0; i<MAXMENUS; i++)
  767.                         if (i<NumMenus)
  768.                             WinSetMenuItemText( popUpMenu, 100*i+100, MenuName[i] );
  769.                         else
  770.                             WinSendMsg( popUpMenu, MM_REMOVEITEM, MPFROM2SHORT(i*100+100,TRUE), 0 );
  771.                     updateTimeDisplay( popUpMenu );
  772.  
  773.                     WinQueryPointerPos( HWND_DESKTOP, &pointData );
  774.                     WinPopupMenu( HWND_DESKTOP, hwndMenu, popUpMenu, pointData.x, pointData.y, 0,
  775.                                   PU_HCONSTRAIN|PU_VCONSTRAIN|PU_MOUSEBUTTON1|PU_MOUSEBUTTON2|PU_MOUSEBUTTON3|PU_KEYBOARD );
  776.                     return 0;
  777.                     }
  778.                 //--------------------------------------------------------------
  779.                 // user wants to shutdown system
  780.                 //--------------------------------------------------------------
  781.                 case TASKLIST_SHUTDOWN: {
  782.                     char text[] = "Are you sure that you want to close all windows and active programs and shutdown your system?  Select OK to continue shutdown.  Select Cancel to end this task.";
  783.                     if (WinMessageBox( HWND_DESKTOP, hwndFrame, text,
  784.                                        "FileBar - Shutdown System", 0,
  785.                                         MB_DEFBUTTON2|MB_MOVEABLE|MB_ICONEXCLAMATION|MB_OKCANCEL) == MBID_CANCEL)
  786.                         return 0;
  787.  
  788.                     writeOptionFile();
  789.                     WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0, SWP_HIDE);
  790.                     WinPostMsg( hwndClient, WM_QUIT, 0, 0 );
  791.                     WinShutdownSystem( WinQueryAnchorBlock( HWND_DESKTOP ), hmq );
  792.                     }
  793.                 //--------------------------------------------------------------
  794.                 // expand or shrink FileBar system menus
  795.                 //--------------------------------------------------------------
  796.                 case FILEBAR_FILEBARMENU: {
  797.                     CHAR menuOn[] = FILEBARMENUON;
  798.                     CHAR menuOff[] = FILEBARMENUOFF;
  799.                     CHAR taskOn[] = TASKMENUON;
  800.                     CHAR taskOff[] = TASKMENUOFF;
  801.  
  802.                     FileBarMenuOn = TRUE - FileBarMenuOn;
  803.                     if (FileBarMenuOn) {
  804.                         WinSetMenuItemText( hwndMenu, FILEBAR_MENU, menuOn);
  805.                         WinSetMenuItemText( hwndMenu, TASKLIST_MENU, taskOn);
  806.                         }
  807.                     else {
  808.                         WinSetMenuItemText( hwndMenu, FILEBAR_MENU, menuOff);
  809.                         WinSetMenuItemText( hwndMenu, TASKLIST_MENU, taskOff);
  810.                         }
  811.                     return 0;
  812.                     }
  813.                 //--------------------------------------------------------------
  814.                 // the user has selected something from the tasklist menu, switch
  815.                 // control to that task, if possible
  816.                 //--------------------------------------------------------------
  817.                 case TASK_SWITCHTO: {
  818.                     CHAR title[] = "FileBar Task Switch Error";
  819.                     CHAR text[] = "ERROR!  Could not locate task!  The task may have already terminated.";
  820.                     HSWITCH switchHandle;
  821.                     switchHandle = WinQuerySwitchHandle( TaskHandle[taskItemSelected - TASKLIST_MENU-1],
  822.                                                          TaskId[taskItemSelected - TASKLIST_MENU-1]);
  823.  
  824.                     if (!switchHandle)
  825.                         WinMessageBox( HWND_DESKTOP, hwnd, text, title, 0,
  826.                                        MB_MOVEABLE|MB_ERROR|MB_OK);
  827.                     else if (WinSwitchToProgram( switchHandle ) != 0)
  828.                         WinMessageBox( HWND_DESKTOP, hwnd, text, title, 0,
  829.                                        MB_MOVEABLE|MB_ERROR|MB_OK);
  830.                     else
  831.                         WinShowWindow( TaskHandle[taskItemSelected - TASKLIST_MENU - 1], TRUE );
  832.                     return 0;
  833.                     }
  834.                 //--------------------------------------------------------------
  835.                 // close the chosen task
  836.                 //--------------------------------------------------------------
  837.                 case TASK_CLOSE: {
  838.                     ULONG numItems;
  839.                     ULONG Buffer;
  840.                     PSWBLOCK SwitchBlockPtr;
  841.                     PID killedTaskId;
  842.                     HWND killedTaskHandle;
  843.  
  844.                     if (checkBeforeDelete) {
  845.                         if (WinMessageBox( HWND_DESKTOP, hwnd,
  846.                                            "Closing may result in the destruction of unsaved data.  Are you sure you want to close this task?",
  847.                                            "FileBar - Close Task", 0,
  848.                                            MB_MOVEABLE|MB_ICONQUESTION|MB_YESNO) == MBID_NO)
  849.                             return 0;
  850.                         }
  851.  
  852.                     killedTaskId = TaskId[taskItemSelected - TASKLIST_MENU - 1];
  853.                     killedTaskHandle = TaskHandle[taskItemSelected - TASKLIST_MENU - 1];
  854.                     WinSendMsg( killedTaskHandle, WM_CLOSE, 0, 0 );
  855.  
  856.                     // get the # of items and the switch list from the system
  857.                     numItems = WinQuerySwitchList( hab, NULL, 0 );
  858.                     Buffer = (numItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
  859.                     PVOID my = new BYTE[Buffer];
  860.                     WinQuerySwitchList( hab, (SWBLOCK*)my, Buffer );
  861.                     SwitchBlockPtr = (PSWBLOCK)(my);
  862.  
  863.                     // if task did not close willingly, kill its process!
  864.                     for (short j = 0; j < numItems; j++ )
  865.                         if (SwitchBlockPtr->aswentry[j].swctl.hwnd == killedTaskHandle)
  866.                             DosKillProcess( DKP_PROCESS, killedTaskId );
  867.                     delete( my );
  868.  
  869.                     return 0;
  870.                     }
  871.                 //-------------------------------------------------------------
  872.                 // maximize the chosen task
  873.                 //-------------------------------------------------------------
  874.                 case TASK_MAX: {
  875.                     HSWITCH switchHandle = WinQuerySwitchHandle( TaskHandle[taskItemSelected - TASKLIST_MENU- 1],
  876.                                                                  TaskId[taskItemSelected - TASKLIST_MENU- 1]);
  877.  
  878.                     WinShowWindow( TaskHandle[taskItemSelected - TASKLIST_MENU- 1], TRUE );
  879.                     WinSetWindowPos( TaskHandle[taskItemSelected - TASKLIST_MENU- 1],
  880.                                      (HWND)0, 0, 0, 0, 0, SWP_MAXIMIZE);
  881.                     WinSwitchToProgram( switchHandle );
  882.                     return 0;
  883.                     }
  884.                 //--------------------------------------------------------------
  885.                 // minimize the chosen task
  886.                 //--------------------------------------------------------------
  887.                 case TASK_MIN: {
  888.                     WinShowWindow( TaskHandle[taskItemSelected - TASKLIST_MENU- 1], TRUE );
  889.                     WinSetWindowPos( TaskHandle[taskItemSelected - TASKLIST_MENU- 1],
  890.                                      (HWND)0, 0, 0, 0, 0, SWP_MINIMIZE);
  891.                     return 0;
  892.                     }
  893.                 //--------------------------------------------------------------
  894.                 // show the chosen task
  895.                 //--------------------------------------------------------------
  896.                 case TASK_SHOW: {
  897.                     WinSetWindowPos( TaskHandle[taskItemSelected - TASKLIST_MENU- 1],
  898.                                      (HWND)0, 0, 0, 0, 0, SWP_SHOW);
  899.                     return 0;
  900.                     }
  901.                 //--------------------------------------------------------------
  902.                 // hide the chosen task
  903.                 //--------------------------------------------------------------
  904.                 case TASK_HIDE: {
  905.                     WinSetWindowPos( TaskHandle[taskItemSelected - TASKLIST_MENU- 1],
  906.                                      (HWND)0, 0, 0, 0, 0, SWP_HIDE);
  907.                     return 0;
  908.                     }
  909.                 //--------------------------------------------------------------
  910.                 // show the display background dialog box
  911.                 //--------------------------------------------------------------
  912.                 case FILEBAR_DISPLAYBACKGROUND: {
  913.                     WinDlgBox(HWND_DESKTOP,
  914.                           hwnd,
  915.                           (PFNWP)backgroundProc,
  916.                           0,
  917.                           BACKGROUNDWIN,
  918.                           (PVOID)NULL);
  919.                     displayBackground();
  920.                     return 0;
  921.                     }
  922.                 //--------------------------------------------------------------
  923.                 // user has altered "confirm on task close" check state
  924.                 //--------------------------------------------------------------
  925.                 case FILEBAR_CONFIRMCLOSE: {
  926.                     checkBeforeDelete = TRUE - checkBeforeDelete;
  927.                     return 0;
  928.                     }
  929.                 //--------------------------------------------------------------
  930.                 // user has altered check state of "always on top" item
  931.                 //--------------------------------------------------------------
  932.                 case FILEBAR_INTERCEPTMSG: {
  933.                     interceptMsg = TRUE - interceptMsg;
  934.                     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  935.                                       allowPopUpMenu, popUpMessageID );
  936.                     return 0;
  937.                     }
  938.                 //--------------------------------------------------------------
  939.                 // show the display background dialog box
  940.                 //--------------------------------------------------------------
  941.                 case FILEBAR_STARTUP: {
  942.                     WinDlgBox(HWND_DESKTOP,
  943.                               hwnd,
  944.                               (PFNWP)startupProc,
  945.                               0,
  946.                               STARTUP_DIALOG,
  947.                              (PVOID)NULL);
  948.                     return 0;
  949.                     }
  950.                 //--------------------------------------------------------------
  951.                 // user has invoked the scheduler
  952.                 //--------------------------------------------------------------
  953.                 case TIMEDATE: {
  954.                     WinDlgBox(HWND_DESKTOP,
  955.                               hwnd,
  956.                               (PFNWP)schedulerProc,
  957.                               0,
  958.                               SCHEDULER,
  959.                               (PVOID)NULL);
  960.                     return 0;
  961.                 }
  962.                 //--------------------------------------------------------------
  963.                 // uer has altered check state of "resize desktop on boot" item
  964.                 //--------------------------------------------------------------
  965.                 case FILEBAR_RESIZEWPS: {
  966.                     maximizeDesktop = TRUE - maximizeDesktop;
  967.                     return 0;
  968.                     }
  969.                 //--------------------------------------------------------------
  970.                 // user wants to change settings of popup menu
  971.                 //--------------------------------------------------------------
  972.                 case FILEBAR_POPMENU: {
  973.                     WinDlgBox(HWND_DESKTOP,
  974.                               hwnd,
  975.                               (PFNWP)popUpOptionsProc,
  976.                               0,
  977.                               POPUPOPTIONS,
  978.                               (PVOID)NULL);
  979.                     return 0;
  980.                     }
  981.                 //--------------------------------------------------------------
  982.                 // the user wants to save current options
  983.                 //--------------------------------------------------------------
  984.                 case FILEBAR_SAVEOPTIONS: {
  985.                     char title[] = "FileBar - Save Menu Configuration";
  986.                     char message[] = "The current user menu configuration has been successfully saved!";
  987.  
  988.                     writeOptionFile();
  989.                     WinMessageBox( HWND_DESKTOP, hwnd, message, title, 0,
  990.                                    MB_MOVEABLE|MB_INFORMATION|MB_OK);
  991.                     return 0;
  992.                 }
  993.                 //--------------------------------------------------------------
  994.                 // the user wants to edit the menu structure
  995.                 //--------------------------------------------------------------
  996.                 case FILEBAR_EDITMENU: {
  997.                     return (VOID*)WinDlgBox(HWND_DESKTOP,
  998.                                             hwnd,
  999.                                             (PFNWP)EditMenuProc,
  1000.                                             0,
  1001.                                             EDITMENU,
  1002.                                             (PVOID)NULL);
  1003.                     }
  1004.                 //--------------------------------------------------------------
  1005.                 // the user wants to select their time/date display options
  1006.                 //--------------------------------------------------------------
  1007.                 case FILEBAR_TIMEOPTION: {
  1008.                     return (VOID*)WinDlgBox(HWND_DESKTOP,
  1009.                                             hwnd,
  1010.                                             (PFNWP)TimeDateProc,
  1011.                                             0,
  1012.                                             TIMEOPTIONS,
  1013.                                             (PVOID)NULL);
  1014.                     }
  1015.                 //--------------------------------------------------------------
  1016.                 // the user wants to get general help on filebar
  1017.                 //--------------------------------------------------------------
  1018.                 case FILEBAR_GENHELP: {
  1019.                     return (VOID*)WinDlgBox(HWND_DESKTOP,
  1020.                                             hwnd,
  1021.                                             (PFNWP)GenericProc,
  1022.                                             0,
  1023.                                             GENERAL_HELP,
  1024.                                             (PVOID)NULL);
  1025.                     }
  1026.                 //--------------------------------------------------------------
  1027.                 // the user wants to see product information for filebar
  1028.                 //--------------------------------------------------------------
  1029.                 case FILEBAR_PRODINFO: {
  1030.                     return (VOID*)WinDlgBox(HWND_DESKTOP,
  1031.                                             hwnd,
  1032.                                             (PFNWP)GenericProc,
  1033.                                             0,
  1034.                                             PRODUCT_INFO,
  1035.                                             (PVOID)NULL);
  1036.                     }
  1037.                 //--------------------------------------------------------------
  1038.                 // the user wishes to move the filebar from its current position
  1039.                 // to either to the top or bottom of the desktop
  1040.                 //--------------------------------------------------------------
  1041.                 case FILEBAR_MOVEBAR: {
  1042.                     if (BarPosition==AT_TOP) {
  1043.                         BarPosition = AT_BOTTOM;
  1044.                         WinSetWindowPos( hwndFrame, (HWND)0, 0, -1,
  1045.                                          ScreenSizeX, MenuHeight, SWP_MOVE);
  1046.                         }
  1047.                     else {
  1048.                         BarPosition = AT_TOP;
  1049.                         WinSetWindowPos( hwndFrame, (HWND)0, 0, (ScreenSizeY-MenuHeight)+1,
  1050.                                          ScreenSizeX, MenuHeight, SWP_MOVE);
  1051.                         }
  1052.                     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  1053.                                       allowPopUpMenu, popUpMessageID );
  1054.                     return 0;
  1055.                     }
  1056.                 //--------------------------------------------------------------
  1057.                 // the user wishes to exit the filebar application
  1058.                 //--------------------------------------------------------------
  1059.                 case FILEBAR_EXIT: {
  1060.                     return (VOID*)WinPostMsg( hwnd, WM_QUIT, 0, 0);
  1061.                     }
  1062.                 //--------------------------------------------------------------
  1063.                 // something besides our menus sent a message, pass the message
  1064.                 // to the system for default processing
  1065.                 //--------------------------------------------------------------
  1066.                 default:
  1067.                     break;
  1068.                 }
  1069.  
  1070.             //------------------------------------------------------------------
  1071.             // the user has selected an item off the user menus.  Activate the
  1072.             // item they have selected
  1073.             //------------------------------------------------------------------
  1074.             if (( command > 99 ) && (command % 100)) {
  1075.                 INT MenuToUpdate = command / 100 - 1;
  1076.                 INT ItemToUpdate = command % 100 - 1;
  1077.  
  1078.                 if ((ItemToUpdate>=MAXITEMS) || (MenuToUpdate>=MAXMENUS))
  1079.                     return 0;
  1080.                 if (MenuToUpdate >= 0)
  1081.                     startApplication( MenuToUpdate, ItemToUpdate );
  1082.                 return 0;
  1083.                 }
  1084.  
  1085.             }
  1086.         //----------------------------------------------------------------------
  1087.         // we were sent a message that we don't care about, pass it onto system
  1088.         // for default processing
  1089.         //----------------------------------------------------------------------
  1090.         default:
  1091.             break;
  1092.         };
  1093.  
  1094.     return WinDefWindowProc(hwnd, msg, mp1, mp2);  // default processing
  1095. }
  1096.  
  1097.  
  1098. ////////////////////////////////////////////////////////////////////////////////
  1099. // readOptionFile - will read the option file (generated by the app) from disk,
  1100. // if it exists and will restore the application to the state in which it was
  1101. // last left
  1102. ////////////////////////////////////////////////////////////////////////////////
  1103. void readOptionFile( void )
  1104. {
  1105.     int currentMenu = 100;
  1106.     FILE *optionFile;
  1107.  
  1108.     //--------------------------------------------------------------------------
  1109.     // if the option file exists on disk, read it in and restore old menu,
  1110.     // otherwise we will return and rely on default values
  1111.     //--------------------------------------------------------------------------
  1112.     //if (settingsPath)
  1113.     //    optionFile = fopen(settingsPath, "rt");
  1114.     //else
  1115.     optionFile = fopen(OPTIONFILE, "rt");
  1116.  
  1117.     if (optionFile != NULL) {
  1118.         ALARMS* alarm;
  1119.         USERMENUITEM* menuItem;
  1120.         RGB2 rgb = {0,0,0,0};
  1121.         ULONG color;
  1122.         INT a,b,c,d,e,f;
  1123.  
  1124.         MenuHeight  = WinQuerySysValue(HWND_DESKTOP, SV_CYMENU) + 2;
  1125.  
  1126.         fscanf(optionFile, "%d %d", &timeOption, &BarPosition);
  1127.         // restore user's desired bar position
  1128.         if (BarPosition==AT_BOTTOM) {
  1129.             WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0 , SWP_MOVE|SWP_RESTORE);
  1130.             WinSetWindowPos( hwndFrame, (HWND)0, 0, -1,
  1131.                              ScreenSizeX, MenuHeight, SWP_MOVE|SWP_SIZE);
  1132.             WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0 , SWP_MOVE|SWP_MINIMIZE);
  1133.             }
  1134.         else {
  1135.             WinSetWindowPos( hwndFrame, (HWND)0, 0, (ScreenSizeY-MenuHeight)+1,
  1136.                              ScreenSizeX, MenuHeight, SWP_MOVE|SWP_SIZE);
  1137.             }
  1138.         setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  1139.                           allowPopUpMenu, popUpMessageID );
  1140.  
  1141.         // restore user's menus and menu choices
  1142.         fscanf(optionFile, "%d", &NumMenus);
  1143.         for (short i = 0; i < NumMenus; i++ ) {
  1144.             readString( optionFile, (CHAR*)&MenuName[i] );
  1145.  
  1146.             WinSendMsg( hwndMenu, MM_SETITEM, MPFROM2SHORT(100*i+100,TRUE),MPFROMP(&menuData[i]));
  1147.             WinSetMenuItemText( hwndMenu, 100*i+100, &MenuName[i]);
  1148.  
  1149.             fscanf(optionFile, "%d", &a);
  1150.             NumItems[i] = (BYTE)(a % 256);
  1151.             for (short j = 0; j < NumItems[i]; j++) {
  1152.                 Menus[i][j] = new USERMENUITEM;
  1153.                 menuItem = Menus[i][j];
  1154.                 readString( optionFile, (CHAR*)&menuItem->ItemName );
  1155.                 readString( optionFile, (CHAR*)&menuItem->ActionToDo );
  1156.                 readString( optionFile, (CHAR*)&menuItem->CmdLnArgs );
  1157.                 readString( optionFile, (CHAR*)&menuItem->Directory );
  1158.                 fscanf( optionFile, "%d", &a );
  1159.                 menuItem->ProgType = a % 1024;
  1160.                 }
  1161.             currentMenu = currentMenu + 100;
  1162.             }
  1163.  
  1164.         readString( optionFile, (CHAR*)&tmpBuffer );
  1165.         if (tmpBuffer[0]!='\0') {
  1166.             WinSetPresParam( hwndMenu, PP_FONTNAMESIZE, sizeof(tmpBuffer), &tmpBuffer );
  1167.             WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0, SWP_RESTORE);
  1168.             resizeMenu();
  1169.             WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0, SWP_MINIMIZE);
  1170.             }
  1171.  
  1172.         fscanf( optionFile, "%d", &checkBeforeDelete );
  1173.         if (fscanf( optionFile, "%d", &FileBarMenuOn )!=EOF) {
  1174.             CHAR menuOn[] = FILEBARMENUON;
  1175.             CHAR menuOff[] = FILEBARMENUOFF;
  1176.             CHAR taskOn[] = TASKMENUON;
  1177.             CHAR taskOff[] = TASKMENUOFF;
  1178.  
  1179.             if (FileBarMenuOn) {
  1180.                 WinSetMenuItemText( hwndMenu, FILEBAR_MENU, menuOn);
  1181.                 WinSetMenuItemText( hwndMenu, TASKLIST_MENU, taskOn);
  1182.                 }
  1183.             else {
  1184.                 WinSetMenuItemText( hwndMenu, FILEBAR_MENU, menuOff);
  1185.                 WinSetMenuItemText( hwndMenu, TASKLIST_MENU, taskOff);
  1186.                 }
  1187.             }
  1188.  
  1189.         if (fscanf( optionFile, "%d", &showBackground )!=EOF) {
  1190.             fscanf( optionFile, "%d", &backgroundAttr );
  1191.             readString( optionFile, (CHAR*)&backgroundBitmap );
  1192.             }
  1193.  
  1194.         for (i=PP_FOREGROUNDCOLOR; i<=PP_BORDERCOLOR; i=i+2)
  1195.             if (fscanf(optionFile, "%ld", &color )!=EOF)
  1196.                 if ( color != NOCOLOR) {
  1197.                     rgb.bRed = (BYTE)(color/65536);
  1198.                     color = color%65536;
  1199.                     rgb.bGreen = (BYTE)(color/256);
  1200.                     color = color%256;
  1201.                     rgb.bBlue = (BYTE)(color);
  1202.                     WinSetPresParam( hwndMenu, i, sizeof(rgb), &rgb);
  1203.                     }
  1204.  
  1205.         for (i=PP_ACTIVECOLOR; i<=PP_INACTIVETEXTBGNDCOLOR; i=i+2)
  1206.             if (fscanf(optionFile, "%ld", &color )!=EOF)
  1207.                 if ( color != NOCOLOR) {
  1208.                     rgb.bRed = (BYTE)(color/65536);
  1209.                     color = color%65536;
  1210.                     rgb.bGreen = (BYTE)(color/256);
  1211.                     color = color%256;
  1212.                     rgb.bBlue = (BYTE)(color);
  1213.                     WinSetPresParam( hwndMenu, i, sizeof(rgb), &rgb);
  1214.                     }
  1215.  
  1216.         if (fscanf(optionFile, "%ld", &color )!=EOF)
  1217.             if ( color != NOCOLOR) {
  1218.                 rgb.bRed = (BYTE)(color/65536);
  1219.                 color = color%65536;
  1220.                 rgb.bGreen = (BYTE)(color/256);
  1221.                 color = color%256;
  1222.                 rgb.bBlue = (BYTE)(color);
  1223.                 WinSetPresParam( hwndMenu, PP_SHADOW, sizeof(rgb), &rgb);
  1224.                 }
  1225.  
  1226.         for (i=PP_MENUFOREGROUNDCOLOR; i<=PP_MENUDISABLEDBGNDCOLOR; i=i+2)
  1227.             if (fscanf(optionFile, "%ld", &color )!=EOF)
  1228.                 if ( color != NOCOLOR) {
  1229.                     rgb.bRed = (BYTE)(color/65536);
  1230.                     color = color%65536;
  1231.                     rgb.bGreen = (BYTE)(color/256);
  1232.                     color = color%256;
  1233.                     rgb.bBlue = (BYTE)(color);
  1234.                     WinSetPresParam( hwndMenu, i, sizeof(rgb), &rgb);
  1235.                     }
  1236.  
  1237.         if (fscanf(optionFile, "%d %d", &DoStartUpList, &numStartItems ) != EOF)
  1238.             for (i=0; i<numStartItems; i++)
  1239.                 fscanf(optionFile, "%d %d", &StartUpMenu[i], &StartUpItem[i] );
  1240.  
  1241.         if (fscanf(optionFile, "%d", &HourlyChime ) != EOF)
  1242.             readString( optionFile, (CHAR*)&hourlyChimeWavFile );
  1243.  
  1244.         // read in current task scheduler tasks
  1245.         if (fscanf(optionFile, "%d %d %d %d", &maximizeDesktop, &repeatTime, &interceptMsg, &numAlarms ) != EOF) {
  1246.             setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  1247.                               allowPopUpMenu, popUpMessageID );
  1248.  
  1249.             for (i=0; i<numAlarms; i++) {
  1250.                 fscanf(optionFile, "%d %d %d %d %d %d", &a,&b,&c,&d,&e,&f);
  1251.                 alarmPtr[i] = new ALARMS;
  1252.                 alarm = alarmPtr[i];
  1253.                 alarm->AlarmHour   = a % 256;
  1254.                 alarm->AlarmMinute = b % 256;
  1255.                 alarm->AlarmMonth  = c % 256;
  1256.                 alarm->AlarmDay    = d % 256;
  1257.                 alarm->AlarmYear   = e % 256;
  1258.                 alarm->options     = f % 256;
  1259.                 readString( optionFile, (CHAR*)&alarm->ActionToDo );
  1260.                 readString( optionFile, (CHAR*)&alarm->ReminderWAV );
  1261.                 }
  1262.         }
  1263.  
  1264.         fscanf(optionFile, "%d %d", &hideFileBar, &allowPopUpMenu );
  1265.         fscanf(optionFile, "%ld", &popUpMessageID );
  1266.  
  1267.         setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  1268.                            allowPopUpMenu, popUpMessageID );
  1269.  
  1270.         fclose( optionFile );
  1271.         }
  1272. }
  1273.  
  1274.  
  1275. ////////////////////////////////////////////////////////////////////////////////
  1276. // writeOptionFile - will write the application state to the option file
  1277. ////////////////////////////////////////////////////////////////////////////////
  1278. void writeOptionFile( void )
  1279. {
  1280.     SHORT currentMenu = 100;
  1281.     FILE *optionFile;
  1282.  
  1283.     //--------------------------------------------------------------------------
  1284.     // if the option file exists on disk, read it in and restore old menu,
  1285.     // otherwise we will return and rely on default values
  1286.     //--------------------------------------------------------------------------
  1287.     //if (settingsPath)
  1288.     //    optionFile = fopen(settingsPath, "wt");
  1289.     //else
  1290.     optionFile = fopen(OPTIONFILE, "wt");
  1291.  
  1292.     if (optionFile == NULL)
  1293.         // if not able to save, alert the user
  1294.         WinMessageBox( HWND_DESKTOP, hwndClient, "Error writing FileBar configuration file!  Application data was NOT saved!",
  1295.                        0, 0, MB_MOVEABLE|MB_ERROR|MB_OK);
  1296.     else {
  1297.         ULONG length;
  1298.         RGB2 rgb;
  1299.         ALARMS* alarm;
  1300.         USERMENUITEM* menuItem;
  1301.  
  1302.         // save user's desired bar position
  1303.         //fprintf(optionFile, "%d %d\n", timeOption, BarPosition);
  1304.         // save user's menus and menu choices
  1305.         //fprintf(optionFile, "%d\n", NumMenus);
  1306.         fprintf(optionFile, "%d %d %d\n", timeOption, BarPosition, NumMenus);
  1307.         for (short i = 0; i < NumMenus; i++ ) {
  1308.             writeString( optionFile, (CHAR*)&MenuName[i] );
  1309.             fprintf(optionFile, "%d\n", NumItems[i]);
  1310.             for (short j = 0; j < NumItems[i]; j++) {
  1311.                 menuItem = Menus[i][j];
  1312.                 writeString( optionFile, (CHAR*)&menuItem->ItemName );
  1313.                 writeString( optionFile, (CHAR*)&menuItem->ActionToDo );
  1314.                 writeString( optionFile, (CHAR*)&menuItem->CmdLnArgs );
  1315.                 writeString( optionFile, (CHAR*)&menuItem->Directory );
  1316.                 fprintf( optionFile, "%d\n", menuItem->ProgType );
  1317.                 }
  1318.             currentMenu = currentMenu + 100;
  1319.             }
  1320.  
  1321.         if (WinQueryPresParam( hwndMenu, PP_FONTNAMESIZE, 0, &length, sizeof(tmpBuffer), &tmpBuffer, 0)!=FALSE)
  1322.             writeString( optionFile, (CHAR*)&tmpBuffer );
  1323.         else
  1324.             fprintf( optionFile, "\"\"\n" );
  1325.         fprintf( optionFile, "%d\n%d\n%d\n%d\n", checkBeforeDelete, FileBarMenuOn, showBackground, backgroundAttr );
  1326.         writeString( optionFile, (CHAR*)&backgroundBitmap );
  1327.  
  1328.         // save menu scheme of colors
  1329.         for (i=PP_FOREGROUNDCOLOR; i<=PP_BORDERCOLOR; i=i+2) {
  1330.             if (WinQueryPresParam( hwndMenu, i, 0, 0, sizeof(rgb), &rgb, 0) != 0)
  1331.                 fprintf(optionFile, "%ld\n", (ULONG)(rgb.bRed*65536+rgb.bGreen*256+rgb.bBlue) );
  1332.             else fprintf(optionFile, "%ld\n", NOCOLOR );
  1333.             }
  1334.  
  1335.         for (i=PP_ACTIVECOLOR; i<=PP_INACTIVETEXTBGNDCOLOR; i=i+2) {
  1336.             if (WinQueryPresParam( hwndMenu, i, 0, 0, sizeof(rgb), &rgb, 0) != 0)
  1337.                 fprintf(optionFile, "%ld\n", (ULONG)(rgb.bRed*65536+rgb.bGreen*256+rgb.bBlue) );
  1338.             else fprintf(optionFile, "%ld\n", NOCOLOR );
  1339.             }
  1340.  
  1341.         if (WinQueryPresParam( hwndMenu, PP_SHADOW, 0, 0, sizeof(rgb), &rgb, 0) != 0)
  1342.             fprintf(optionFile, "%ld\n", (ULONG)(rgb.bRed*65536+rgb.bGreen*256+rgb.bBlue) );
  1343.         else fprintf(optionFile, "%ld\n", NOCOLOR );
  1344.  
  1345.         for (i=PP_MENUFOREGROUNDCOLOR; i<=PP_MENUDISABLEDBGNDCOLOR; i=i+2) {
  1346.             if (WinQueryPresParam( hwndMenu, i, 0, 0, sizeof(rgb), &rgb, 0) != 0)
  1347.                 fprintf(optionFile, "%ld\n", (ULONG)(rgb.bRed*65536+rgb.bGreen*256+rgb.bBlue) );
  1348.             else fprintf(optionFile, "%ld\n", NOCOLOR );
  1349.             }
  1350.  
  1351.         fprintf(optionFile, "%d\n%d\n", DoStartUpList, numStartItems );
  1352.         for (i=0; i<numStartItems; i++)
  1353.             fprintf(optionFile, "%d\n%d\n", StartUpMenu[i], StartUpItem[i] );
  1354.  
  1355.         fprintf(optionFile, "%d\n", HourlyChime );
  1356.         writeString( optionFile, (CHAR*)&hourlyChimeWavFile );
  1357.  
  1358.         // save current task scheduler items
  1359.         fprintf(optionFile, "%d %d %d %d\n", maximizeDesktop, repeatTime, interceptMsg, numAlarms );
  1360.         for (i=0; i<numAlarms; i++) {
  1361.             alarm = alarmPtr[i];
  1362.             fprintf(optionFile, "%d %d %d %d %d %d\n", alarm->AlarmHour,
  1363.                                                        alarm->AlarmMinute,
  1364.                                                        alarm->AlarmMonth,
  1365.                                                        alarm->AlarmDay,
  1366.                                                        alarm->AlarmYear,
  1367.                                                        alarm->options );
  1368.             writeString( optionFile, (CHAR*)alarm->ActionToDo );
  1369.             writeString( optionFile, (CHAR*)alarm->ReminderWAV );
  1370.             }
  1371.         fprintf( optionFile, "%d %d\n", hideFileBar, allowPopUpMenu );
  1372.         fprintf( optionFile, "%ld\n", popUpMessageID );
  1373.  
  1374.         fclose( optionFile );
  1375.         }
  1376. }
  1377.  
  1378.  
  1379. ////////////////////////////////////////////////////////////////////////////////
  1380. // readString will read a sequence of characters that is bounded on both sides
  1381. // by quote (") characters (We can't use fscanf because it won't read spaces)
  1382. ////////////////////////////////////////////////////////////////////////////////
  1383. VOID readString( FILE* stream, CHAR* buffer )
  1384. {
  1385.     if (stringTerminator)
  1386.         do                                       // search for first " character
  1387.           if (fscanf( stream, "%c", buffer)==EOF) break;
  1388.           while ( (*buffer) != stringTerminator);
  1389. //        do {                               // search for first " character
  1390. //            if (fscanf( stream, "%c", buffer)==EOF) break;
  1391. //            } while ( (*buffer) != stringTerminator);
  1392.     else {
  1393.         do                                       // search for first " character
  1394.           if (fscanf( stream, "%c", buffer)==EOF) break;
  1395.           while ( ((*buffer) !='\"') && ((*buffer) != TERMCHAR) );
  1396. //        do {                               // search for first " character
  1397. //            if (fscanf( stream, "%c", buffer)==EOF) break;
  1398. //            } while ( ((*buffer) !='\"') && ((*buffer) != TERMCHAR) );
  1399.         stringTerminator= (*buffer);
  1400.         }
  1401.     buffer--;
  1402.     do {                               // keep putting characters into the buffer
  1403.         buffer++;                      // " character
  1404.         if (fscanf( stream, "%c", buffer)==EOF) break;
  1405.     } while ( (*buffer) != stringTerminator);
  1406.     *buffer = '\0';                    // store a NULL to terminate the string
  1407. }
  1408.  
  1409.  
  1410. ////////////////////////////////////////////////////////////////////////////////
  1411. // Message handler for a generic information-only dialog box (help & prod info)
  1412. ////////////////////////////////////////////////////////////////////////////////
  1413. MRESULT EXPENTRY GenericProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  1414. {
  1415.    switch( msg )
  1416.     {
  1417.         //----------------------------------------------------------------------
  1418.         // when the dialog is being initialized, center it on desktop
  1419.         //----------------------------------------------------------------------
  1420.         case WM_INITDLG: {
  1421.             SWP swp;
  1422.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  1423.             WinSetWindowPos( hWnd, (HWND)0,
  1424.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  1425.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  1426.                              0, 0, SWP_MOVE);
  1427.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  1428.             }
  1429.         //----------------------------------------------------------------------
  1430.         // if we receive any system message, dismiss the dialog box
  1431.         //----------------------------------------------------------------------
  1432.         case WM_COMMAND:
  1433.         {
  1434.             WinDismissDlg( hWnd, TRUE );
  1435.             return 0;
  1436.         }
  1437.         //----------------------------------------------------------------------
  1438.         // if nothing further we want to intercept, pass message onto system
  1439.         //----------------------------------------------------------------------
  1440.         default:
  1441.             break;
  1442.     }
  1443.     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  1444. }
  1445.  
  1446.  
  1447. ////////////////////////////////////////////////////////////////////////////////
  1448. // starts or restarts a timer to signal our program when the next minute occurs
  1449. ////////////////////////////////////////////////////////////////////////////////
  1450. VOID restartTimer( VOID )
  1451. {
  1452.     struct tm *time_now;
  1453.     time_t currentTime;
  1454.  
  1455.     tzset();
  1456.     time(¤tTime);
  1457.     time_now = localtime( ¤tTime );
  1458.     timeSync = FALSE;
  1459.  
  1460.     timerNumber = WinStartTimer( hab, hwndClient, TIMERID, (60-(time_now->tm_sec))*1000);
  1461. }
  1462.  
  1463.  
  1464. ////////////////////////////////////////////////////////////////////////////////
  1465. // ringChime - play a .WAV file sent to us as the parameter.
  1466. ////////////////////////////////////////////////////////////////////////////////
  1467. VOID ringChime( CHAR* soundFile )
  1468. {
  1469.     APIRET rc;
  1470.     char mesg[MAXPATH+384];
  1471.     RXSTRING  INSTORE[2];
  1472.     RXSTRING  retstr;
  1473.     SHORT ReturnCode;
  1474.     LONG offset = 0;
  1475.  
  1476.     if (soundFile == 0)
  1477.         return;
  1478.     if (soundFile[0] == 0) {
  1479.         WinAlarm( HWND_DESKTOP, WA_NOTE );
  1480.         return;
  1481.         }
  1482.  
  1483.     MakeHourglassPointer ();                       // switch to hourglass cursor
  1484.     offset = offset + sprintf(mesg+offset, "/* */\r\n");
  1485.     offset = offset + sprintf(mesg+offset, "rc = call RxFuncAdd('mciRxInit','MCIAPI',,\r\n'mciRxInit')\r\n");
  1486.     offset = offset + sprintf(mesg+offset, "rc = call mciRxInit()\r\n");
  1487.     offset = offset + sprintf(mesg+offset, "rc = mciRxSendString('open waveaudio',\r\n'alias wave shareable wait',,\r\n'RetStr','0','0')\r\n");
  1488.     offset = offset + sprintf(mesg+offset, "rc = mciRxSendString('load wave %s wait',,\r\n'RetStr','0','0')\r\n", soundFile );
  1489.     offset = offset + sprintf(mesg+offset, "rc = mciRxSendString('play wave wait',,\r\n'RetStr','0','0')\r\n" );
  1490.     offset = offset + sprintf(mesg+offset, "rc = mciRxSendString('close wave wait',,\r\n'RetStr','0','0')\r\n" );
  1491.     offset = offset + sprintf(mesg+offset, "call mciRxExit\r\n" );
  1492.     sprintf(mesg+offset, "exit\r\n\x1A\0" );
  1493.  
  1494.     INSTORE[0].strptr=mesg;
  1495.     INSTORE[0].strlength=strlen(mesg);
  1496.     INSTORE[1].strptr=NULL;
  1497.     INSTORE[1].strlength=0;
  1498.  
  1499.     rc = rexxStart((LONG)0,
  1500.               (PRXSTRING)0,
  1501.               (PSZ)LAUNCHFILE,
  1502.               (PRXSTRING)INSTORE,
  1503.               (PSZ)"CMD",
  1504.               (LONG)RXCOMMAND,
  1505.               (PRXSYSEXIT)0,
  1506.               (SHORT*)&ReturnCode,
  1507.               (PRXSTRING)&retstr);
  1508.  
  1509.     // if there was an error (ie: no MMPM), make a system beep
  1510.     if (rc)
  1511.         WinAlarm( HWND_DESKTOP, WA_NOTE );
  1512.  
  1513.     MakeArrowPointer ();                      // switch back to arrow pointer,
  1514. }
  1515.  
  1516.  
  1517. ////////////////////////////////////////////////////////////////////////////////
  1518. // update the time displayed on the FileBar menubar
  1519. ////////////////////////////////////////////////////////////////////////////////
  1520. VOID updateTimeDisplay( HWND window ) {
  1521.     char tmp1[24];
  1522.     char tmp2[24];
  1523.     CHAR buffer[64] = { '\0' };
  1524.     struct tm *time_now;
  1525.     time_t currentTime;
  1526.  
  1527.     tzset();
  1528.     time(¤tTime);
  1529.     time_now = localtime( ¤tTime );
  1530.  
  1531.     if ((timeOption == TIMEONLY) || (timeOption == TIMEANDDATE)) {
  1532.         strftime( tmp1, sizeof(tmp1), "%I", time_now);
  1533.         strftime( tmp2, sizeof(tmp2), ":%M %p  ", time_now);
  1534.         if (tmp1[0] == '0')
  1535.             tmp1[0]=' ';
  1536.         strcat( buffer, tmp1 );
  1537.         strcat( buffer, tmp2 );
  1538.         }
  1539.     if (timeOption == TIMEANDDATE)
  1540.         strcat( buffer, " " );
  1541.     if ((timeOption == DATEONLY) || (timeOption == TIMEANDDATE)) {
  1542.         strftime( tmp1, sizeof(tmp1), "%B", time_now);
  1543.         strftime( tmp2, sizeof(tmp2), "%d, %Y  ", time_now);
  1544.  
  1545.         if (tmp2[0] == '0') {
  1546.             tmp2[0] = ' ';
  1547.             strcat( buffer, tmp1 );
  1548.             strcat( buffer, tmp2 );
  1549.             }
  1550.         else {
  1551.             strcat( buffer, tmp1 );
  1552.             strcat( buffer, " \0" );
  1553.             strcat( buffer, tmp2 );
  1554.             }
  1555.         }
  1556.     else if (timeOption == OTHERTIMEONLY)
  1557.         strftime( buffer, sizeof(buffer), "%H:%M  ", time_now);
  1558.     else if (timeOption == OTHERDATEONLY)
  1559.         strftime( buffer, sizeof(buffer), "%d %B %Y  ", time_now);
  1560.     else if (timeOption == OTHERTIMEANDDATE) {
  1561.         strftime( tmp1, sizeof(tmp1), "%H:%M ", time_now );
  1562.         strftime( tmp2, sizeof(tmp2), "%d %B %Y  ", time_now );
  1563.         if (tmp1[0] == '0')
  1564.             tmp1[0] = ' ';
  1565.         if (tmp2[0] == '0')
  1566.             tmp2[0] = ' ';
  1567.         else
  1568.             strcat( tmp1, " " );
  1569.         strcat( buffer, tmp1 );
  1570.         strcat( buffer, tmp2 );
  1571.         }
  1572.     if (buffer[0]=='0')
  1573.         buffer[0]=' ';
  1574.  
  1575.     WinSetMenuItemText( window, TIMEDATE, &buffer );
  1576. }
  1577.  
  1578.  
  1579. ////////////////////////////////////////////////////////////////////////////////
  1580. // displayTimeDate is used to check to see if time/date on the FileBar menu
  1581. // needs updateing and also to check to see if any alarms need to be serviced
  1582. ////////////////////////////////////////////////////////////////////////////////
  1583. VOID displayTimeDate( VOID )
  1584. {
  1585.     struct tm *time_now;
  1586.     time_t currentTime;
  1587.  
  1588.     tzset();
  1589.     time(¤tTime);
  1590.     time_now = localtime( ¤tTime );
  1591.  
  1592.  
  1593.     if (timeOption != NONE)
  1594.         if (((timeOption != DATEONLY) && (timeOption != OTHERDATEONLY)) ||
  1595.              (time_now->tm_min == 0) )
  1596.             updateTimeDisplay( hwndMenu );
  1597.  
  1598.     if (time_now->tm_min == 30)
  1599.         alreadyChimed = FALSE;
  1600.  
  1601.     if ((!alreadyChimed) && (time_now->tm_min == 0) && (HourlyChime)) {
  1602.         alreadyChimed = TRUE;
  1603.         ringChime( hourlyChimeWavFile );
  1604.         }
  1605.  
  1606.     checkAlarms( time_now->tm_hour, time_now->tm_min, time_now->tm_mon,
  1607.                  time_now->tm_mday, time_now->tm_year );
  1608. }
  1609.  
  1610.  
  1611. ////////////////////////////////////////////////////////////////////////////////
  1612. // resets the file dialog control structure so its OK to use next time
  1613. ////////////////////////////////////////////////////////////////////////////////
  1614. VOID resetFileDialog( VOID )
  1615. {
  1616.     SHORT s;
  1617.  
  1618.     s=strlen(fileDlgInfo.szFullFile);
  1619.     while((fileDlgInfo.szFullFile[s]!='\\') && (s>=0))
  1620.         s--;
  1621.  
  1622.     if (fileDlgInfo.szFullFile[s]=='\\')
  1623.         fileDlgInfo.szFullFile[s+1]='\0';
  1624.     else
  1625.         fileDlgInfo.szFullFile[0]='\0';
  1626. }
  1627.  
  1628. ////////////////////////////////////////////////////////////////////////////////
  1629. // Message handler for time and date option setting dialog
  1630. ////////////////////////////////////////////////////////////////////////////////
  1631. MRESULT EXPENTRY TimeDateProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  1632. {
  1633.    switch( msg )
  1634.     {
  1635.         //----------------------------------------------------------------------
  1636.         // when the dialog is being initialized, center it on desktop and check
  1637.         // the appropriate radio button for whatever setting they currently have
  1638.         //----------------------------------------------------------------------
  1639.         case WM_INITDLG: {
  1640.             SWP swp;
  1641.  
  1642.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  1643.             WinSetWindowPos( hWnd, (HWND)0,
  1644.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  1645.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  1646.                              0, 0, SWP_MOVE);
  1647.             WinSendDlgItemMsg( hWnd, timeOption, BM_SETCHECK,
  1648.                                MPFROM2SHORT( 1, 0 ), 0);
  1649.             WinCheckButton( hWnd, PLAYCHIME, HourlyChime );
  1650.  
  1651.             WinSendDlgItemMsg( hWnd, CHIMEWAVFILE, EM_SETTEXTLIMIT,
  1652.                                MPFROM2SHORT( MAXACTIONSTRINGLENGTH-1, 0 ), 0 );
  1653.             WinSetDlgItemText( hWnd, CHIMEWAVFILE, hourlyChimeWavFile);
  1654.  
  1655.             break;
  1656.             }
  1657.         //----------------------------------------------------------------------
  1658.         // we received a change in control, update menubar time
  1659.         //----------------------------------------------------------------------
  1660.         case WM_CONTROL:
  1661.         {
  1662.             timeOption = NONE;
  1663.             if (WinQueryButtonCheckstate( hWnd, TIMEONLY ))
  1664.                 timeOption = TIMEONLY;
  1665.             else if (WinQueryButtonCheckstate( hWnd, DATEONLY ))
  1666.                 timeOption = DATEONLY;
  1667.             else if (WinQueryButtonCheckstate( hWnd, TIMEANDDATE ))
  1668.                 timeOption = TIMEANDDATE;
  1669.             else if (WinQueryButtonCheckstate( hWnd, OTHERTIMEONLY ))
  1670.                 timeOption = OTHERTIMEONLY;
  1671.             else if (WinQueryButtonCheckstate( hWnd, OTHERDATEONLY ))
  1672.                 timeOption = OTHERDATEONLY;
  1673.             else if (WinQueryButtonCheckstate( hWnd, OTHERTIMEANDDATE ))
  1674.                 timeOption = OTHERTIMEANDDATE;
  1675.  
  1676.             WinStopTimer( hab, hwndClient, timerNumber );
  1677.             restartTimer();
  1678.             updateTimeDisplay( hwndMenu );
  1679.             break;
  1680.         }
  1681.  
  1682.         //----------------------------------------------------------------------
  1683.         // if we receive any system message, dismiss dialog and store new option
  1684.         //----------------------------------------------------------------------
  1685.         case WM_COMMAND:
  1686.         {
  1687.             USHORT command = SHORT1FROMMP(mp1);
  1688.             switch( command ) {
  1689.             case TESTWAVEFILE: {
  1690.                 WinQueryDlgItemText( hWnd, CHIMEWAVFILE, sizeof(hourlyChimeWavFile), hourlyChimeWavFile);
  1691.                 ringChime( hourlyChimeWavFile );
  1692.                 return 0;
  1693.                 }
  1694.             case FINDWAVFILE: {
  1695.                 CHAR title[] = "FileBar - Find a Hourly Chime .WAV file";
  1696.                 HWND hwndDialog;
  1697.  
  1698.                 fileDlgInfo.fl = FDS_OPEN_DIALOG|FDS_CENTER;
  1699.                 fileDlgInfo.pszTitle = title;
  1700.  
  1701.                 strcpy(oldDirectory, fileDlgInfo.szFullFile);
  1702.                 strcat(fileDlgInfo.szFullFile, "*.WAV\0");
  1703.  
  1704.                 hwndDialog = WinFileDlg( HWND_DESKTOP, hWnd, &fileDlgInfo );
  1705.                 if (hwndDialog && (fileDlgInfo.lReturn == DID_OK)) {
  1706.                     strcpy( hourlyChimeWavFile, fileDlgInfo.szFullFile );
  1707.                     resetFileDialog();
  1708.                     WinSetDlgItemText( hWnd, CHIMEWAVFILE, hourlyChimeWavFile );
  1709.                     }
  1710.                 else
  1711.                     strcpy(fileDlgInfo.szFullFile, oldDirectory);
  1712.                 return 0;
  1713.                 }
  1714.             }
  1715.  
  1716.             timeOption = NONE;
  1717.             if (WinQueryButtonCheckstate( hWnd, TIMEONLY ))
  1718.                 timeOption = TIMEONLY;
  1719.             else if (WinQueryButtonCheckstate( hWnd, DATEONLY ))
  1720.                 timeOption = DATEONLY;
  1721.             else if (WinQueryButtonCheckstate( hWnd, TIMEANDDATE ))
  1722.                 timeOption = TIMEANDDATE;
  1723.             else if (WinQueryButtonCheckstate( hWnd, OTHERTIMEONLY ))
  1724.                 timeOption = OTHERTIMEONLY;
  1725.             else if (WinQueryButtonCheckstate( hWnd, OTHERDATEONLY ))
  1726.                 timeOption = OTHERDATEONLY;
  1727.             else if (WinQueryButtonCheckstate( hWnd, OTHERTIMEANDDATE ))
  1728.                 timeOption = OTHERTIMEANDDATE;
  1729.  
  1730.             HourlyChime = WinQueryButtonCheckstate( hWnd, PLAYCHIME );
  1731.  
  1732.             // stop current timer (if one exists) and start a new one
  1733.             // display new time and date according to new option setting
  1734.             WinStopTimer( hab, hwndClient, timerNumber );
  1735.             restartTimer();
  1736.             WinQueryDlgItemText( hWnd, CHIMEWAVFILE, sizeof(hourlyChimeWavFile), hourlyChimeWavFile);
  1737.             WinDismissDlg( hWnd, TRUE );
  1738.             return 0;
  1739.         }
  1740.         //----------------------------------------------------------------------
  1741.         // if nothing further we want to intercept, pass message onto system
  1742.         //----------------------------------------------------------------------
  1743.         default:
  1744.             break;
  1745.     }
  1746.     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  1747. }
  1748.  
  1749.  
  1750. ////////////////////////////////////////////////////////////////////////////////
  1751. // EditMenuProc - the message handler for editing a menu dialog box
  1752. ////////////////////////////////////////////////////////////////////////////////
  1753. MRESULT EXPENTRY EditMenuProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  1754. {
  1755.     switch( msg )
  1756.     {
  1757.         //----------------------------------------------------------------------
  1758.         // if double-clicked an entry, allow them to edit it
  1759.         //----------------------------------------------------------------------
  1760.         case WM_CONTROL:
  1761.         {
  1762.             if ((SHORT1FROMMP(mp1)==CURMENULIST) && (SHORT2FROMMP(mp1)==LN_ENTER))
  1763.                 return WinSendMsg( hWnd, WM_COMMAND, MPFROM2SHORT( EDITMENUBUTTON, 0 ), mp2 );
  1764.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  1765.         }
  1766.         //----------------------------------------------------------------------
  1767.         // when the dialog is being initialized, center it on desktop and put
  1768.         // the current data into appropriate list boxes
  1769.         //----------------------------------------------------------------------
  1770.         case WM_INITDLG: {
  1771.             SWP swp;
  1772.  
  1773.             for (short i=0; i<NumMenus; i++)
  1774.                 WinSendDlgItemMsg( hWnd, CURMENULIST, LM_INSERTITEM,
  1775.                                    MPFROM2SHORT( LIT_END, 0 ),
  1776.                                    MenuName[i] );
  1777.             if (NumMenus > 0) {
  1778.                 WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
  1779.                                    MPFROM2SHORT( 0, 0 ),
  1780.                                    MPFROM2SHORT( TRUE, 0 ) );
  1781.                 }
  1782.             else {
  1783.                 WinEnableControl( hWnd, EDITMENUBUTTON, FALSE );
  1784.                 WinEnableControl( hWnd, REMOVEMENU, FALSE );
  1785.                 WinEnableControl( hWnd, MOVEMENULEFT, FALSE );
  1786.                 WinEnableControl( hWnd, MOVEMENURIGHT, FALSE );
  1787.                 }
  1788.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  1789.             WinSetWindowPos( hWnd, (HWND)0,
  1790.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  1791.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  1792.                              0, 0, SWP_MOVE);
  1793.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  1794.             }
  1795.         //----------------------------------------------------------------------
  1796.         // process a command message received from the system
  1797.         //----------------------------------------------------------------------
  1798.         case WM_COMMAND: {
  1799.             USHORT command = SHORT1FROMMP(mp1);
  1800.             switch( command )
  1801.                 {
  1802.                 //--------------------------------------------------------------
  1803.                 // if they pressed OK button, dismiss dialog and return
  1804.                 //--------------------------------------------------------------
  1805.                 case DID_OK: {
  1806.                     WinDismissDlg( hWnd, TRUE );
  1807.                     return 0;
  1808.                     }
  1809.                 //--------------------------------------------------------------
  1810.                 // they want to edit a menu
  1811.                 //--------------------------------------------------------------
  1812.                 case EDITMENUBUTTON: {
  1813.                     if (NumMenus == 0) {
  1814.                         WinAlarm(HWND_DESKTOP, WA_ERROR);
  1815.                         return 0;
  1816.                         }
  1817.                     // find out what menu they've selected in list box
  1818.                     MenuSelection = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURMENULIST,
  1819.                                                                      LM_QUERYSELECTION,
  1820.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  1821.                                                                      0 ) );
  1822.                     // display edit menu dialog box
  1823.                     WinDlgBox(HWND_DESKTOP,
  1824.                               hWnd,
  1825.                               (PFNWP)EditItemProc,
  1826.                               0,
  1827.                               EDITITEM,
  1828.                               (PVOID)NULL);
  1829.                     // change the item in the list box and select it
  1830.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_DELETEALL, 0, 0 );
  1831.                     for (short i=0; i<NumMenus; i++)
  1832.                         WinSendDlgItemMsg( hWnd, CURMENULIST, LM_INSERTITEM,
  1833.                                            MPFROM2SHORT( LIT_END, 0 ),
  1834.                                            MenuName[i] );
  1835.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
  1836.                                        MPFROM2SHORT( MenuSelection, 0 ),
  1837.                                        MPFROM2SHORT( TRUE, 0 ) );
  1838.                     return 0;
  1839.                     }
  1840.                 //--------------------------------------------------------------
  1841.                 // the user wants to add another menu to the menubar
  1842.                 //--------------------------------------------------------------
  1843.                 case ADDMENU: {
  1844.                     MenuSelection = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURMENULIST,
  1845.                                                                      LM_QUERYSELECTION,
  1846.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  1847.                                                                      0 ) );
  1848.                     // error if no room for another menu
  1849.                     if (NumMenus >= MAXMENUS) {
  1850.                         WinMessageBox( HWND_DESKTOP, hWnd,
  1851.                                        "Error!  Maximum number of user-menus already defined!",
  1852.                                        "Add A Menu", 0,
  1853.                                        MB_MOVEABLE|MB_ERROR|MB_OK);
  1854.                         return 0;
  1855.                         }
  1856.                     WinDlgBox(HWND_DESKTOP,
  1857.                               hWnd,
  1858.                               (PFNWP)AddAMenuProc,
  1859.                               0,
  1860.                               ADDAMENU,
  1861.                               (PVOID)NULL);
  1862.                     // if first menu to be added, enable buttons
  1863.                     if (NumMenus > 0) {
  1864.                         WinEnableControl( hWnd, EDITMENUBUTTON, TRUE );
  1865.                         WinEnableControl( hWnd, REMOVEMENU, TRUE );
  1866.                         WinEnableControl( hWnd, MOVEMENULEFT, TRUE );
  1867.                         WinEnableControl( hWnd, MOVEMENURIGHT, TRUE );
  1868.                         }
  1869.  
  1870.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_DELETEALL, 0, 0 );
  1871.                     for (short i=0; i<NumMenus; i++)
  1872.                         WinSendDlgItemMsg( hWnd, CURMENULIST, LM_INSERTITEM,
  1873.                                            MPFROM2SHORT( LIT_END, 0 ),
  1874.                                            MenuName[i] );
  1875.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
  1876.                                        MPFROM2SHORT( MenuSelection, 0 ),
  1877.                                        MPFROM2SHORT( TRUE, 0 ) );
  1878.                     return 0;
  1879.                     }
  1880.                 //--------------------------------------------------------------
  1881.                 // the user wants to remove a menu from the menu list box
  1882.                 //--------------------------------------------------------------
  1883.                 case REMOVEMENU: {
  1884.                     if (NumMenus == 0) {
  1885.                         WinAlarm(HWND_DESKTOP, WA_WARNING);
  1886.                         return 0;
  1887.                         }
  1888.  
  1889.                     if (NumMenus > 0)
  1890.                         if (WinMessageBox( HWND_DESKTOP, hWnd,
  1891.                                            "If you remove this menu, there will be no way to recover it.  Are you sure you want to remove this menu?",
  1892.                                            "Remove Menu", 0,
  1893.                                            MB_MOVEABLE|MB_WARNING|MB_YESNO|MB_DEFBUTTON2) == MBID_YES ) {
  1894.                             short index = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURMENULIST,
  1895.                                                                            LM_QUERYSELECTION,
  1896.                                                                            MPFROM2SHORT( LIT_FIRST, 0 ),
  1897.                                                                            0 ) );
  1898.                             MENUITEM menuItem;
  1899.  
  1900.                             // delete it from the list box
  1901.                             WinSendDlgItemMsg( hWnd, CURMENULIST, LM_DELETEITEM,
  1902.                                                MPFROM2SHORT( index, 0 ), 0 );
  1903.  
  1904.                             // delete it from menu structure
  1905.                             MakeHourglassPointer ();
  1906.                             WinSetMenuItemText( hwndMenu, 100*index+100, "" );
  1907.                             for (short i=index+1; i<MAXMENUS; i++)
  1908.                                 SwapTwoMenus( i-1, i );
  1909.  
  1910.                             ////////////////////////////////////////////////////
  1911.                             for (i=0; i<NumItems[MAXMENUS-1]; i++)
  1912.                                 delete Menus[MAXMENUS-1][i];
  1913.                             ////////////////////////////////////////////////////
  1914.                             NumItems[MAXMENUS-1] = 0;
  1915.                             MenuName[MAXMENUS-1][0] = '\0';
  1916.                             if (NumMenus > 0) {
  1917.                                 int newIndex = index-1;
  1918.                                 if (0 > newIndex)
  1919.                                     newIndex = 0;
  1920.  
  1921.                                 if (index == NumMenus-1)
  1922.                                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
  1923.                                                        MPFROM2SHORT( newIndex, 0 ),
  1924.                                                        MPFROM2SHORT( TRUE, 0 ) );
  1925.                                 else
  1926.                                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
  1927.                                                        MPFROM2SHORT( index, 0 ),
  1928.                                                        MPFROM2SHORT( TRUE, 0 ) );
  1929.                                 }
  1930.                             WinSendMsg( hwndMenu, MM_QUERYITEM, MPFROM2SHORT(NumMenus*100,TRUE),MPFROMP(&menuData[index]));
  1931.                             menuItem = menuData[index];
  1932.                             menuItem.afStyle = MIS_STATIC;
  1933.                             menuItem.afAttribute = MIA_DISABLED;
  1934.                             WinSendMsg( hwndMenu, MM_SETITEM, MPFROM2SHORT(NumMenus*100,TRUE),MPFROMP(&menuItem));
  1935.                             WinSetMenuItemText( hwndMenu, 100*MAXMENUS, "" );
  1936.                             NumItems[ NumMenus ] = 0;
  1937.                             NumMenus--;
  1938.  
  1939.                             // if we deleted only menu, disable menu buttons
  1940.                             if (NumMenus == 0) {
  1941.                                 WinEnableControl( hWnd, EDITMENUBUTTON, FALSE );
  1942.                                 WinEnableControl( hWnd, REMOVEMENU, FALSE );
  1943.                                 WinEnableControl( hWnd, MOVEMENULEFT, FALSE );
  1944.                                 WinEnableControl( hWnd, MOVEMENURIGHT, FALSE );
  1945.                                 }
  1946.                             MakeArrowPointer ();
  1947.                             }
  1948.                     return 0;
  1949.                     }
  1950.                 //--------------------------------------------------------------
  1951.                 // move menu left in menu structure
  1952.                 //--------------------------------------------------------------
  1953.                 case MOVEMENULEFT: {
  1954.                     short index = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURMENULIST,
  1955.                                                              LM_QUERYSELECTION,
  1956.                                                              MPFROM2SHORT( LIT_FIRST, 0 ),
  1957.                                                              0 ) );
  1958.                     if ((NumMenus == 0) || (index == 0)) {
  1959.                         WinAlarm(HWND_DESKTOP, WA_WARNING);
  1960.                         return 0;
  1961.                         }
  1962.                     MakeHourglassPointer ();
  1963.                     SwapTwoMenus( index-1, index );
  1964.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_DELETEITEM,
  1965.                                        MPFROM2SHORT( index, 0 ), 0 );
  1966.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_INSERTITEM,
  1967.                                        MPFROM2SHORT( index-1, 0 ), MenuName[index-1] );
  1968.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
  1969.                                        MPFROM2SHORT( index-1, 0 ),
  1970.                                        MPFROM2SHORT( TRUE, 0 ) );
  1971.                     MakeArrowPointer ();
  1972.                     return 0;
  1973.                     }
  1974.                 //--------------------------------------------------------------
  1975.                 // move menu right in menu structure
  1976.                 //--------------------------------------------------------------
  1977.                 case MOVEMENURIGHT: {
  1978.                     short index = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURMENULIST,
  1979.                                                              LM_QUERYSELECTION,
  1980.                                                              MPFROM2SHORT( LIT_FIRST, 0 ),
  1981.                                                              0 ) );
  1982.                     if ((NumMenus == 0) || (index == (NumMenus)-1)) {
  1983.                         WinAlarm(HWND_DESKTOP, WA_WARNING);
  1984.                         return 0;
  1985.                         }
  1986.                     SwapTwoMenus( index, index+1 );
  1987.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_DELETEITEM,
  1988.                                        MPFROM2SHORT( index, 0 ), 0 );
  1989.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_INSERTITEM,
  1990.                                        MPFROM2SHORT( index+1, 0 ), MenuName[index+1] );
  1991.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
  1992.                                        MPFROM2SHORT( index+1, 0 ),
  1993.                                        MPFROM2SHORT( TRUE, 0 ) );
  1994.                     return 0;
  1995.                     }
  1996.                 //--------------------------------------------------------------
  1997.                 // nothing we care about, pass it onto the system default proc
  1998.                 //--------------------------------------------------------------
  1999.                 default:
  2000.                     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2001.                 }
  2002.             }
  2003.         //----------------------------------------------------------------------
  2004.         // if nothing further we want to intercept, pass message onto system
  2005.         //----------------------------------------------------------------------
  2006.         default:
  2007.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2008.     }
  2009. }
  2010.  
  2011.  
  2012. ////////////////////////////////////////////////////////////////////////////////
  2013. // SwapTwoMenus will swap the FileBar stored information entries for two menus
  2014. // indicated by menu1 and menu2.  The text on the displayed menubar will also
  2015. // be changed to indicate the swap.
  2016. ////////////////////////////////////////////////////////////////////////////////
  2017. void SwapTwoMenus( short menu1, short menu2 )
  2018. {
  2019.     USERMENUITEM* tmpPtr;
  2020.     BYTE t2;
  2021.  
  2022.     for (short i=0; i<MAXITEMS; i++) {
  2023.         tmpPtr = Menus[menu1][i];
  2024.         Menus[menu1][i] = Menus[menu2][i];
  2025.         Menus[menu2][i] = tmpPtr;
  2026.         }
  2027.  
  2028.     t2 = NumItems[menu2];
  2029.     NumItems[menu2] = NumItems[menu1];
  2030.     NumItems[menu1] = t2;
  2031.  
  2032.     strcpy( tmpBuffer, MenuName[menu1] );
  2033.     strcpy( MenuName[menu1], MenuName[menu2] );
  2034.     strcpy( MenuName[menu2], tmpBuffer );
  2035.  
  2036.     WinSetMenuItemText( hwndMenu, 100+menu1*100, MenuName[menu1] );
  2037.     WinSetMenuItemText( hwndMenu, 100+menu2*100, MenuName[menu2] );
  2038. }
  2039.  
  2040.  
  2041. ////////////////////////////////////////////////////////////////////////////////
  2042. // AddAMenuProc - message handler for the dialog box that allows the user to
  2043. // add a menu to the menubar
  2044. ////////////////////////////////////////////////////////////////////////////////
  2045. MRESULT EXPENTRY AddAMenuProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  2046. {
  2047.    switch( msg )
  2048.     {
  2049.         //----------------------------------------------------------------------
  2050.         // when the dialog is being initialized, center it on desktop and put
  2051.         // the current data into controls
  2052.         //----------------------------------------------------------------------
  2053.         case WM_INITDLG: {
  2054.             SWP swp;
  2055.             WinSendDlgItemMsg( hWnd, MENUNAME, EM_SETTEXTLIMIT,
  2056.                                MPFROM2SHORT( MAXMENUNAMELENGTH-1, 0 ), 0 );
  2057.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  2058.             WinSetWindowPos( hWnd, (HWND)0,
  2059.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  2060.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  2061.                              0, 0, SWP_MOVE);
  2062.             break;
  2063. //            return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2064.             }
  2065.         //----------------------------------------------------------------------
  2066.         // process a command message received from the system
  2067.         //----------------------------------------------------------------------
  2068.         case WM_COMMAND:
  2069.         {
  2070.             USHORT command = SHORT1FROMMP(mp1);
  2071.             switch( command )
  2072.                 {
  2073.                 //--------------------------------------------------------------
  2074.                 // user press OK button.  Add the menu name they entered into
  2075.                 // the menu structure and return
  2076.                 //--------------------------------------------------------------
  2077.                 case DID_OK: {
  2078.                     WinQueryDlgItemText( hWnd, MENUNAME, MAXMENUNAMELENGTH, MenuName[NumMenus]);
  2079.                     NumItems[NumMenus] = 0;
  2080.                     menuData[NumMenus].afStyle = 0;
  2081.                     menuData[NumMenus].afAttribute = 0;
  2082.                     WinSendMsg( hwndMenu, MM_SETITEM, MPFROM2SHORT(100*NumMenus+100,TRUE),MPFROMP(&menuData[NumMenus]));
  2083.                     WinSetMenuItemText( hwndMenu, 100*NumMenus+100, &MenuName[NumMenus]);
  2084.                     MenuSelection = NumMenus;
  2085.                     NumMenus++;
  2086.                     WinDismissDlg( hWnd, TRUE );
  2087.                     return 0;
  2088.                     }
  2089.                 //--------------------------------------------------------------
  2090.                 // they decided not to add a menu, dismiss dialog and return
  2091.                 //--------------------------------------------------------------
  2092.                 case DID_CANCEL: {
  2093.                     WinDismissDlg( hWnd, TRUE );
  2094.                     return 0;
  2095.                     }
  2096.                 //--------------------------------------------------------------
  2097.                 // nothing we care about, pass on for default processing
  2098.                 //--------------------------------------------------------------
  2099.                 default:
  2100.                     break;
  2101.                 }
  2102.         }
  2103.         // ---------------------------------------------------------------------
  2104.         // if nothing further we want to intercept, pass message onto system
  2105.         // ---------------------------------------------------------------------
  2106.         default:
  2107.             break;
  2108.     }
  2109.     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2110. }
  2111.  
  2112.  
  2113. ////////////////////////////////////////////////////////////////////////////////
  2114. // Swap menu items item1 and item2 on menu Menu in the menu information arrays
  2115. ////////////////////////////////////////////////////////////////////////////////
  2116. VOID SwapTwoItems(SHORT Menu, SHORT item1, SHORT item2)
  2117. {
  2118.     USERMENUITEM* tmpPtr;
  2119.  
  2120.     tmpPtr = Menus[Menu][item1];
  2121.     Menus[Menu][item1] = Menus[Menu][item2];
  2122.     Menus[Menu][item2] = tmpPtr;
  2123. }
  2124.  
  2125.  
  2126. ////////////////////////////////////////////////////////////////////////////////
  2127. // updateItemList - refreshes the contents of the item list list-box in a dialog
  2128. ////////////////////////////////////////////////////////////////////////////////
  2129. VOID updateItemList( HWND hWnd )
  2130. {
  2131.     CHAR Separator[] = SEPARATOR;
  2132.     WinSendDlgItemMsg( hWnd, ITEMMENU, LM_DELETEALL, 0, 0 );
  2133.     for (short i=0; i<NumItems[MenuSelection]; i++)
  2134.         if (Menus[MenuSelection][i]->ItemName[0] != '\0')
  2135.             WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
  2136.                                MPFROM2SHORT( LIT_END, 0 ),
  2137.                                Menus[MenuSelection][i]->ItemName );
  2138.         else
  2139.             WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
  2140.                                MPFROM2SHORT( LIT_END, 0 ),
  2141.                                Separator );
  2142.     if (NumItems[MenuSelection] > 0)
  2143.         WinSendDlgItemMsg( hWnd, ITEMMENU, LM_SELECTITEM,
  2144.                            MPFROM2SHORT( ItemSelection, 0 ),
  2145.                            MPFROM2SHORT( TRUE, 0 ) );
  2146. }
  2147.  
  2148.  
  2149. ////////////////////////////////////////////////////////////////////////////////
  2150. // EditItemProc - the message handler for the edit menu item dialog box
  2151. ////////////////////////////////////////////////////////////////////////////////
  2152. MRESULT EXPENTRY EditItemProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  2153. {
  2154.     switch( msg )
  2155.     {
  2156.         //----------------------------------------------------------------------
  2157.         // when the dialog is being initialized, center it on desktop and put
  2158.         // the current data into control fields
  2159.         //----------------------------------------------------------------------
  2160.         case WM_INITDLG: {
  2161.             SWP swp;
  2162.             WinSendDlgItemMsg( hWnd, MENUNAME, EM_SETTEXTLIMIT,
  2163.                                MPFROM2SHORT( MAXMENUNAMELENGTH-1, 0 ), 0 );
  2164.             WinSetDlgItemText( hWnd, MENUNAME, MenuName[MenuSelection]);
  2165.             ItemSelection = 0;
  2166.             updateItemList( hWnd );
  2167.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  2168.             WinSetWindowPos( hWnd, (HWND)0,
  2169.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  2170.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  2171.                              0, 0, SWP_MOVE);
  2172.             break;
  2173. //            return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2174.             }
  2175.         //----------------------------------------------------------------------
  2176.         // if there is a control message, update enabled status of buttons
  2177.         //----------------------------------------------------------------------
  2178.         case WM_CONTROL:
  2179.         {
  2180.             if ((SHORT1FROMMP(mp1)==ITEMMENU) && (SHORT2FROMMP(mp1)==LN_ENTER))
  2181.                 return WinSendMsg( hWnd, WM_COMMAND, MPFROM2SHORT( CHANGEITEM, 0 ), mp2 );
  2182.             break;
  2183. //            return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2184.         }
  2185.         //----------------------------------------------------------------------
  2186.         // process a command message received from the system
  2187.         //----------------------------------------------------------------------
  2188.         case WM_COMMAND:
  2189.         {
  2190.             USHORT command = SHORT1FROMMP(mp1);
  2191.             switch( command )
  2192.                 {
  2193.                 //--------------------------------------------------------------
  2194.                 // insert a separator into item list, if there is room
  2195.                 //--------------------------------------------------------------
  2196.                 case INSERTSEPARATOR: {
  2197.                     ItemSelection = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
  2198.                                                                      LM_QUERYSELECTION,
  2199.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  2200.                                                                      0 ) );
  2201.                     if (NumItems[MenuSelection] >= MAXITEMS-1) {
  2202.                         // error and return if no room
  2203.                         WinMessageBox( HWND_DESKTOP, hWnd,
  2204.                                        "Error!  Maximum number of items for this menu already defined!",
  2205.                                        "Add A Separator", 0,
  2206.                                        MB_MOVEABLE|MB_ERROR|MB_OK);
  2207.                         return 0;
  2208.                         }
  2209.  
  2210.                     // since this is a separator, blank out launch information
  2211.                     ItemSelection = 0;
  2212.                     if (NumItems[MenuSelection] > 0)
  2213.                         for (short i=NumItems[MenuSelection]-1; i>=0; i--)
  2214.                             SwapTwoItems( MenuSelection, i, i+1 );
  2215.  
  2216.                     Menus[MenuSelection][ItemSelection] = new USERMENUITEM;
  2217.                     Menus[MenuSelection][ItemSelection]->ItemName[0]='\0';
  2218.                     NumItems[MenuSelection]++;
  2219. //                    UpdateMenu[MenuSelection] = TRUE;
  2220.                     updateItemList( hWnd );
  2221.                     return 0;
  2222.                     }
  2223.                 //--------------------------------------------------------------
  2224.                 // user wants to add an item to the current menu
  2225.                 //--------------------------------------------------------------
  2226.                 case ADDITEM: {
  2227.                     ItemSelection = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
  2228.                                                                      LM_QUERYSELECTION,
  2229.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  2230.                                                                      0 ) );
  2231.                     // error and return if no room for another item
  2232.                     if (NumItems[MenuSelection] >= MAXITEMS) {
  2233.                         WinMessageBox( HWND_DESKTOP, hWnd,
  2234.                                        "Error!  Maximum number of items for this menu already defined!",
  2235.                                        "Add Item", 0,
  2236.                                        MB_MOVEABLE|MB_ERROR|MB_OK);
  2237.                         return 0;
  2238.                         }
  2239.                     // get new item via add item dialog box
  2240.                     WinDlgBox(HWND_DESKTOP,
  2241.                               hWnd,
  2242.                               (PFNWP)AddAnItemProc,
  2243.                               0,
  2244.                               ADDANITEM,
  2245.                               (PVOID)NULL);
  2246.                     // update item list with possible new item
  2247.                     updateItemList( hWnd );
  2248.                     return 0;
  2249.                     }
  2250.                 //--------------------------------------------------------------
  2251.                 // user wants to change a menu item
  2252.                 //--------------------------------------------------------------
  2253.                 case CHANGEITEM: {
  2254.                     ItemSelection = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
  2255.                                                                      LM_QUERYSELECTION,
  2256.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  2257.                                                                      0 ) );
  2258.                     if ((NumItems[MenuSelection] == 0) || (Menus[MenuSelection][ItemSelection]->ItemName[0] == '\0')) {
  2259.                         WinAlarm(HWND_DESKTOP, WA_WARNING);
  2260.                         return 0;
  2261.                         }
  2262.                     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, FALSE,
  2263.                                       allowPopUpMenu, popUpMessageID );
  2264.                     WinDlgBox(HWND_DESKTOP,
  2265.                               hWnd,
  2266.                               (PFNWP)EditItemDataProc,
  2267.                               0,
  2268.                               EDITITEMDATA,
  2269.                               (PVOID)NULL);
  2270.                     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  2271.                                       allowPopUpMenu, popUpMessageID );
  2272.                     updateItemList( hWnd );
  2273.                     return 0;
  2274.                     }
  2275.                 //--------------------------------------------------------------
  2276.                 // move item down in menu order
  2277.                 //--------------------------------------------------------------
  2278.                 case MOVEITEMDOWN: {
  2279.                     CHAR Separator[] = SEPARATOR;
  2280.                     short i = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
  2281.                                                                LM_QUERYSELECTION,
  2282.                                                                MPFROM2SHORT( LIT_FIRST, 0 ),
  2283.                                                                0 ) );
  2284.                     if ((i == NumItems[MenuSelection]-1) || (NumItems[MenuSelection] == 0)) {
  2285.                         WinAlarm(HWND_DESKTOP, WA_WARNING);
  2286.                         return 0;
  2287.                         }
  2288.                     SwapTwoItems( MenuSelection, i, i+1 );
  2289.                     WinSendDlgItemMsg( hWnd, ITEMMENU, LM_DELETEITEM,
  2290.                                        MPFROM2SHORT( i, 0 ),
  2291.                                        MPFROM2SHORT( TRUE, 0 ) );
  2292.                     if (Menus[MenuSelection][i+1]->ItemName[0] == '\0')
  2293.                         WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
  2294.                                            MPFROM2SHORT( i+1, 0 ),
  2295.                                            Separator );
  2296.                     else WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
  2297.                                             MPFROM2SHORT( i+1, 0 ),
  2298.                                             &Menus[MenuSelection][i+1]->ItemName );
  2299.                     WinSendDlgItemMsg( hWnd, ITEMMENU, LM_SELECTITEM,
  2300.                                        MPFROM2SHORT( i+1, 0 ),
  2301.                                        MPFROM2SHORT( TRUE, 0 ) );
  2302.                     return 0;
  2303.                     }
  2304.                 //--------------------------------------------------------------
  2305.                 // move item up in menu order
  2306.                 //--------------------------------------------------------------
  2307.                 case MOVEITEMUP: {
  2308.                     CHAR Separator[] = SEPARATOR;
  2309.                     short i = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
  2310.                                                                LM_QUERYSELECTION,
  2311.                                                                MPFROM2SHORT( LIT_FIRST, 0 ),
  2312.                                                                0 ) );
  2313.                     if ((i == 0) || (NumItems[MenuSelection] == 0)) {
  2314.                         WinAlarm(HWND_DESKTOP, WA_WARNING);
  2315.                         return 0;
  2316.                         }
  2317.                     SwapTwoItems( MenuSelection, i-1, i );
  2318.                     WinSendDlgItemMsg( hWnd, ITEMMENU, LM_DELETEITEM,
  2319.                                        MPFROM2SHORT( i, 0 ),
  2320.                                        MPFROM2SHORT( TRUE, 0 ) );
  2321.                     if (Menus[MenuSelection][i-1]->ItemName[0] == '\0')
  2322.                         WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
  2323.                                            MPFROM2SHORT( i-1, 0 ),
  2324.                                            Separator );
  2325.                     else WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
  2326.                                             MPFROM2SHORT( i-1, 0 ),
  2327.                                             &Menus[MenuSelection][i-1]->ItemName );
  2328.                     WinSendDlgItemMsg( hWnd, ITEMMENU, LM_SELECTITEM,
  2329.                                        MPFROM2SHORT( i-1, 0 ),
  2330.                                        MPFROM2SHORT( TRUE, 0 ) );
  2331.                     return 0;
  2332.                     }
  2333.                 //--------------------------------------------------------------
  2334.                 // remove a menu item
  2335.                 //--------------------------------------------------------------
  2336.                 case REMOVEITEM: {
  2337.                     if (NumItems[MenuSelection] == 0) {
  2338.                         WinAlarm(HWND_DESKTOP, WA_WARNING);
  2339.                         return 0;
  2340.                         }
  2341.  
  2342.                     if (NumItems[MenuSelection] > 0)
  2343.                         if (WinMessageBox( HWND_DESKTOP, hWnd,
  2344.                                            "If you remove this item, there will be no way to recover it.  Are you sure you want to remove this item?",
  2345.                                            "Remove Item", 0,
  2346.                                            MB_MOVEABLE|MB_WARNING|MB_YESNO|MB_DEFBUTTON2) == MBID_YES ) {
  2347.                             short index = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
  2348.                                                                            LM_QUERYSELECTION,
  2349.                                                                            MPFROM2SHORT( LIT_FIRST, 0 ),
  2350.                                                                            0 ) );
  2351.                             WinSendDlgItemMsg( hWnd, ITEMMENU, LM_DELETEITEM,
  2352.                                                MPFROM2SHORT( index, 0 ), 0 );
  2353.  
  2354.                             delete Menus[MenuSelection][index];
  2355.                             for (short i=index; i<MAXITEMS-1; i++)
  2356.                                 Menus[MenuSelection][i] = Menus[MenuSelection][i+1];
  2357.  
  2358.                             if (NumItems[MenuSelection] > 0) {
  2359.                                 int newIndex = index-1;
  2360.                                 if (0 > newIndex)
  2361.                                     newIndex = 0;
  2362.  
  2363.                                 if (index == NumItems[MenuSelection]-1)
  2364.                                     WinSendDlgItemMsg( hWnd, ITEMMENU, LM_SELECTITEM,
  2365.                                                        MPFROM2SHORT( newIndex, 0 ),
  2366.                                                        MPFROM2SHORT( TRUE, 0 ) );
  2367.                                 else
  2368.                                     WinSendDlgItemMsg( hWnd, ITEMMENU, LM_SELECTITEM,
  2369.                                                        MPFROM2SHORT( index, 0 ),
  2370.                                                        MPFROM2SHORT( TRUE, 0 ) );
  2371.                                 }
  2372.                             NumItems[MenuSelection]--;
  2373.                             }
  2374.                     return 0;
  2375.                     }
  2376.                 //--------------------------------------------------------------
  2377.                 // user is done editing a menu, save menu name and return
  2378.                 //--------------------------------------------------------------
  2379.                 case DID_OK: {
  2380.                     WinQueryDlgItemText( hWnd, MENUNAME, MAXMENUNAMELENGTH, MenuName[MenuSelection]);
  2381.                     WinSetMenuItemText( hwndMenu, 100*MenuSelection+100, &MenuName[MenuSelection]);
  2382.                     WinDismissDlg( hWnd, TRUE );
  2383.                     return 0;
  2384.                     }
  2385.                 //--------------------------------------------------------------
  2386.                 // not a message we care about, pass it onto the system
  2387.                 //--------------------------------------------------------------
  2388.                 default:
  2389.                     break;
  2390. //                    return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2391.                 }
  2392.         }
  2393.         //----------------------------------------------------------------------
  2394.         // if nothing further we want to intercept, pass message onto system
  2395.         //----------------------------------------------------------------------
  2396.         default:
  2397.            break;
  2398. //           return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2399.         }
  2400.     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2401. }
  2402.  
  2403.  
  2404. ////////////////////////////////////////////////////////////////////////////////
  2405. // update the enable/disabled state of the program type buttons
  2406. ////////////////////////////////////////////////////////////////////////////////
  2407. void updateEditItemWindow( HWND hWnd )
  2408. {
  2409.     SHORT value = TRUE;
  2410.  
  2411.     if (WinQueryButtonCheckstate( hWnd, STARTWPS ))
  2412.         value = FALSE;
  2413.  
  2414.     WinEnableControl( hWnd, MAXIMIZED, value );
  2415.     WinEnableControl( hWnd, MINIMIZED, value );
  2416.     WinEnableControl( hWnd, FOLDER, value );
  2417.     WinEnableControl( hWnd, DOSWIN, value );
  2418.     WinEnableControl( hWnd, DOSFS, value );
  2419.     WinEnableControl( hWnd, OS2WIN, value );
  2420.     WinEnableControl( hWnd, OS2FS, value );
  2421.     WinEnableControl( hWnd, WINOS2WIN, value );
  2422.     WinEnableControl( hWnd, WINOS2FS, value );
  2423.     WinEnableControl( hWnd, PMAPP, value );
  2424.     WinEnableControl( hWnd, SETTINGSBUTTON, TRUE-value );
  2425.  
  2426.     if (WinQueryButtonCheckstate( hWnd, FOLDER )) {
  2427.         WinEnableControl( hWnd, MAXIMIZED, FALSE );
  2428.         WinEnableControl( hWnd, MINIMIZED, FALSE );
  2429.         }
  2430.  
  2431.     if ((WinQueryButtonCheckstate( hWnd, FOLDER )) || (WinQueryButtonCheckstate( hWnd, PMAPP )))
  2432.         WinEnableControl( hWnd, STARTWPS, FALSE );
  2433.     else
  2434.         WinEnableControl( hWnd, STARTWPS, TRUE );
  2435.  
  2436.     if (Menus[MenuSelection][ItemSelection]->ActionToDo[0]=='\0')
  2437.         WinEnableControl( hWnd, SETTINGSBUTTON, FALSE );
  2438. }
  2439.  
  2440.  
  2441. ////////////////////////////////////////////////////////////////////////////////
  2442. // updateEditItemData - update the check states of all the buttons for the
  2443. // program item we are currently editing
  2444. ////////////////////////////////////////////////////////////////////////////////
  2445. void updateEditItemData( HWND hWnd )
  2446. {
  2447.     // put item name and length of longest possible name in entry field
  2448.     USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2449.     WinSendDlgItemMsg( hWnd, ITEMNAME, EM_SETTEXTLIMIT,
  2450.                        MPFROM2SHORT( MAXITEMNAMELENGTH-1, 0 ), 0 );
  2451.     WinSetDlgItemText( hWnd, ITEMNAME, menuItem->ItemName);
  2452.     // put path name and length of longest possible name in entry field
  2453.     WinSendDlgItemMsg( hWnd, PATHNAME, EM_SETTEXTLIMIT,
  2454.                        MPFROM2SHORT( MAXACTIONSTRINGLENGTH-1, 0 ), 0 );
  2455.     WinSetDlgItemText( hWnd, PATHNAME, menuItem->ActionToDo);
  2456.     // put argument and length of longest possible in entry field
  2457.     WinSendDlgItemMsg( hWnd, ARGUMENTS, EM_SETTEXTLIMIT,
  2458.                        MPFROM2SHORT( MAXARGSTRINGLENGTH-1, 0 ), 0 );
  2459.     WinSetDlgItemText( hWnd, ARGUMENTS, menuItem->CmdLnArgs);
  2460.     // put directory and length of longest possible directory in entry field
  2461.     WinSendDlgItemMsg( hWnd, DIRECTORY, EM_SETTEXTLIMIT,
  2462.                        MPFROM2SHORT( MAXDIRSTRINGLENGTH-1, 0 ), 0 );
  2463.     WinSetDlgItemText( hWnd, DIRECTORY, menuItem->Directory);
  2464.     // set appropriate radio button for program startup option
  2465.     WinCheckButton( hWnd, MAXIMIZED, FALSE );
  2466.     WinCheckButton( hWnd, MINIMIZED, FALSE );
  2467.     SHORT ProgType = menuItem->ProgType;
  2468.     if (ProgType & STARTMAX)
  2469.         WinCheckButton( hWnd, MAXIMIZED, TRUE );
  2470.     else if (ProgType & STARTMIN)
  2471.         WinCheckButton( hWnd, MINIMIZED, TRUE );
  2472.     // set appropriate radio button for program startup option
  2473.     if (ProgType & PM)
  2474.         WinCheckButton( hWnd, PMAPP, TRUE );
  2475.     else if (ProgType & WPSFOLDER)
  2476.         WinCheckButton( hWnd, FOLDER, TRUE );
  2477.     else if ( (ProgType & DOS) && (ProgType & WINDOWED))
  2478.         WinCheckButton( hWnd, DOSWIN, TRUE );
  2479.     else if ( (ProgType & DOS) && (ProgType & FULLSCREEN))
  2480.         WinCheckButton( hWnd, DOSFS, TRUE );
  2481.     else if ( (ProgType & OS2) && (ProgType & WINDOWED))
  2482.         WinCheckButton( hWnd, OS2WIN, TRUE );
  2483.     else if ( (ProgType & OS2) && (ProgType & FULLSCREEN))
  2484.         WinCheckButton( hWnd, OS2FS, TRUE );
  2485.     else if ( (ProgType & WINOS2) && (ProgType & WINDOWED))
  2486.         WinCheckButton( hWnd, WINOS2WIN, TRUE );
  2487.     else if ( (ProgType & WINOS2) && (ProgType & FULLSCREEN))
  2488.         WinCheckButton( hWnd, WINOS2FS, TRUE );
  2489.     if (ProgType & STARTASWPS)
  2490.         WinCheckButton( hWnd, STARTWPS, TRUE );
  2491.     else
  2492.         WinCheckButton( hWnd, STARTWPS, FALSE );
  2493.     updateEditItemWindow( hWnd );
  2494. }
  2495.  
  2496.  
  2497. ////////////////////////////////////////////////////////////////////////////////
  2498. // message handler for the dialog "edit an item's values"
  2499. ////////////////////////////////////////////////////////////////////////////////
  2500. MRESULT EXPENTRY EditItemDataProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  2501. {
  2502.     switch( msg )
  2503.     {
  2504.         //----------------------------------------------------------------------
  2505.         // if the object being drug over us is a single object, allow drag
  2506.         //----------------------------------------------------------------------
  2507.         case DM_DRAGOVER: {
  2508.             ULONG cbBuffer;
  2509.             DRAGITEM dragItem;
  2510.             PDRAGINFO dragInfoPtr;
  2511.             INT numObjects;
  2512.  
  2513.             dragInfoPtr = (PDRAGINFO)mp1;
  2514.             DrgAccessDraginfo(dragInfoPtr);
  2515.             numObjects = dragInfoPtr->cditem;
  2516.             cbBuffer = sizeof(DRAGITEM);
  2517.             DrgQueryDragitem( dragInfoPtr, cbBuffer, &dragItem, 0 );
  2518.             DrgFreeDraginfo(dragInfoPtr);
  2519.  
  2520.             // allow anything, if sent by itself, to be dropped on us
  2521.             if (numObjects == 1)
  2522.                 return MPFROM2SHORT( DOR_DROP, DO_UNKNOWN );
  2523.             return MPFROM2SHORT( DOR_NEVERDROP, DO_UNKNOWN );
  2524.             }
  2525.         //----------------------------------------------------------------------
  2526.         // allow the dropping of a WPS object to our window.  Once dropped, get
  2527.         // necessary info and fill in dialog with the info we retrieve
  2528.         //----------------------------------------------------------------------
  2529.         case DM_DROP: {
  2530.             PDRAGINFO dragInfoPtr;
  2531.             ULONG cbBuffer;
  2532.             DRAGITEM dragItem;
  2533.  
  2534.             dragInfoPtr = (PDRAGINFO)mp1;
  2535.             DrgAccessDraginfo(dragInfoPtr);
  2536.  
  2537.             cbBuffer = sizeof(DRAGITEM);
  2538.             DrgQueryDragitem( dragInfoPtr, cbBuffer, &dragItem, 0 );
  2539.  
  2540.             USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2541.             // get menu item name
  2542.             DrgQueryStrName( dragItem.hstrTargetName, MAXITEMNAMELENGTH, menuItem->ItemName);
  2543.             // get default directory
  2544.             DrgQueryStrName( dragItem.hstrContainerName, MAXDIRSTRINGLENGTH, menuItem->Directory);
  2545.             // get path name
  2546.             DrgQueryStrName( dragItem.hstrSourceName, MAXACTIONSTRINGLENGTH, menuItem->ActionToDo);
  2547.  
  2548.             menuItem->ProgType = WPSFOLDER;
  2549.             WinCheckButton( hWnd, FOLDER, TRUE );
  2550.  
  2551.             DrgFreeDraginfo(dragInfoPtr);
  2552.             updateEditItemData( hWnd );
  2553.             WinSetFocus( HWND_DESKTOP, hWnd );
  2554.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2555.             }
  2556.         //----------------------------------------------------------------------
  2557.         // when the dialog is being initialized, center it on desktop and put
  2558.         // the current data into control fields
  2559.         //----------------------------------------------------------------------
  2560.         case WM_INITDLG: {
  2561.             SWP swp;
  2562.  
  2563.             // center dialog on screen
  2564.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  2565.             WinSetWindowPos( hWnd, (HWND)0,
  2566.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  2567.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  2568.                              0, 0, SWP_MOVE);
  2569.  
  2570.             // save data in case of cancel or restore
  2571.             USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2572.             oldProgType = menuItem->ProgType;
  2573.             strcpy( oldItemName, menuItem->ItemName );
  2574.             strcpy( oldDirectory, menuItem->Directory );
  2575.             strcpy( oldAction, menuItem->ActionToDo );
  2576.             strcpy( oldCmdLn, menuItem->CmdLnArgs );
  2577.  
  2578.             updateEditItemData( hWnd );
  2579.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2580.             }
  2581.         //----------------------------------------------------------------------
  2582.         // we received a control message, update enabling of buttons
  2583.         //----------------------------------------------------------------------
  2584.         case WM_CONTROL:
  2585.         {
  2586.             // make sure either maximize -or- minimize is checked, never both
  2587.             if ((SHORT1FROMMP(mp1)==MAXIMIZED) && (SHORT2FROMMP(mp1)==BN_CLICKED))
  2588.                 WinCheckButton( hWnd, MINIMIZED, FALSE );
  2589.             if ((SHORT1FROMMP(mp1)==MINIMIZED) && (SHORT2FROMMP(mp1)==BN_CLICKED))
  2590.                 WinCheckButton( hWnd, MAXIMIZED, FALSE );
  2591.             updateEditItemWindow( hWnd );
  2592.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2593.         }
  2594.         //----------------------------------------------------------------------
  2595.         // process a command message received from the system
  2596.         //----------------------------------------------------------------------
  2597.         case WM_COMMAND:
  2598.         {
  2599.             USHORT command = SHORT1FROMMP(mp1);
  2600.             switch( command )
  2601.                 {
  2602.                 //--------------------------------------------------------------
  2603.                 // open the settings notebook and allow user modifications
  2604.                 //--------------------------------------------------------------
  2605.                 case SETTINGSBUTTON: {
  2606.                     HOBJECT object;
  2607.  
  2608.                     // open settings for current program in dialog controls
  2609.                     USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2610.                     WinQueryDlgItemText( hWnd, ITEMNAME, MAXITEMNAMELENGTH,
  2611.                                          menuItem->ItemName);
  2612.                     WinQueryDlgItemText( hWnd, PATHNAME, MAXACTIONSTRINGLENGTH,
  2613.                                          menuItem->ActionToDo);
  2614.                     WinQueryDlgItemText( hWnd, ARGUMENTS, MAXARGSTRINGLENGTH,
  2615.                                          menuItem->CmdLnArgs);
  2616.                     WinQueryDlgItemText( hWnd, DIRECTORY, MAXDIRSTRINGLENGTH,
  2617.                                          menuItem->Directory);
  2618.  
  2619.                     if (menuItem->ProgType & WPSFOLDER)
  2620.                         sprintf(tmpBuffer, "%s%s\0", menuItem->Directory,
  2621.                                 menuItem->ActionToDo);
  2622.                     else
  2623.                         sprintf(tmpBuffer, "%s\0", menuItem->ActionToDo);
  2624.  
  2625.                     object = WinQueryObject( tmpBuffer );
  2626.                     if (object==NULLHANDLE) {
  2627.                         if (FileBarIsShell)
  2628.                             WinMessageBox( HWND_DESKTOP, hwndFrame, "You cannot access WPS settings when FileBar has replaced the WPS as your active shell.", "FileBar Error!", 0,
  2629.                                            MB_MOVEABLE|MB_OK|MB_ERROR);
  2630.                         else WinMessageBox( HWND_DESKTOP, hwndFrame, "Could not locate the specified WPS object!\n\nThe pathname and/or directory you specified may not be correct.", "FileBar Error!", 0,
  2631.                                             MB_MOVEABLE|MB_OK|MB_ERROR);
  2632.                         return 0;
  2633.                         }
  2634.  
  2635.                     WinSetObjectData( object, "OPEN=SETTINGS" );
  2636.                     return 0;
  2637.                     }
  2638.                 //--------------------------------------------------------------
  2639.                 // the user wants to find a file to call as a menu item.  Hook
  2640.                 // into OS/2's file dialog procedure to ease the finding process
  2641.                 // for us to program!  Then once a file is selected, fill in
  2642.                 // the program path, directory and query the application for its
  2643.                 // application type and mark the appropriate radio button
  2644.                 //--------------------------------------------------------------
  2645.                 case FINDFILE: {
  2646.                     CHAR title[] = "FileBar - Find A File To Add";
  2647.                     ULONG s, t;
  2648.                     HWND hwndDialog;
  2649.  
  2650.                     fileDlgInfo.fl = FDS_OPEN_DIALOG|FDS_CENTER;
  2651.                     fileDlgInfo.pszTitle = title;
  2652.                     strcat(fileDlgInfo.szFullFile, "*.*\0");
  2653.  
  2654.                     USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2655.                     hwndDialog = WinFileDlg( HWND_DESKTOP, hWnd, &fileDlgInfo );
  2656.                     if (hwndDialog && (fileDlgInfo.lReturn == DID_OK)) {
  2657.  
  2658.                         strcpy( menuItem->ActionToDo, fileDlgInfo.szFullFile );
  2659.  
  2660.                         s=strlen(fileDlgInfo.szFullFile);
  2661.                         while((fileDlgInfo.szFullFile[s]!='\\') && (s>=0))
  2662.                             s--;
  2663.  
  2664.                         t = 0;
  2665.                         while (t<s)
  2666.                             menuItem->Directory[t] = fileDlgInfo.szFullFile[t++];
  2667.                         menuItem->Directory[t] = '\0';
  2668.  
  2669.                         DosQueryAppType( menuItem->ActionToDo, &t);
  2670.                         menuItem->ProgType = OS2 + WINDOWED;
  2671.                         if (t == FAPPTYP_WINDOWAPI)
  2672.                             menuItem->ProgType = PM;
  2673.                         if (t == FAPPTYP_WINDOWCOMPAT)
  2674.                             menuItem->ProgType = OS2 + WINDOWED;
  2675.                         if (t == FAPPTYP_NOTWINDOWCOMPAT)
  2676.                             menuItem->ProgType = OS2 + FULLSCREEN;
  2677.                         if (t == FAPPTYP_DOS)
  2678.                             menuItem->ProgType = DOS + WINDOWED;
  2679.                         if ((t == FAPPTYP_WINDOWSREAL) || (t == FAPPTYP_WINDOWSPROT))
  2680.                             menuItem->ProgType = WINOS2 + FULLSCREEN;
  2681.  
  2682.                         updateEditItemData( hWnd );
  2683.                         updateEditItemWindow( hWnd );
  2684.  
  2685.                         if (fileDlgInfo.szFullFile[s]=='\\')
  2686.                             fileDlgInfo.szFullFile[s+1]='\0';
  2687.                         else
  2688.                             fileDlgInfo.szFullFile[0]='\0';
  2689.                         }
  2690.                     else
  2691.                         fileDlgInfo.szFullFile[0]='\0';
  2692.                     return 0;
  2693.                     }
  2694.                 //--------------------------------------------------------------
  2695.                 // user pressed Reset, restore old settings and continue
  2696.                 //--------------------------------------------------------------
  2697.                 case RESETBUTTON: {
  2698.                     USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2699.                     menuItem->ProgType = oldProgType;
  2700.                     strcpy( menuItem->ItemName, oldItemName );
  2701.                     strcpy( menuItem->Directory, oldDirectory );
  2702.                     strcpy( menuItem->ActionToDo, oldAction );
  2703.                     strcpy( menuItem->CmdLnArgs, oldCmdLn );
  2704.                     updateEditItemData( hWnd );
  2705.                     return 0;
  2706.                     }
  2707.                 //--------------------------------------------------------------
  2708.                 // user pressed CANCEL, restore old item data
  2709.                 //--------------------------------------------------------------
  2710.                 case DID_CANCEL: {
  2711.                     USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2712.                     menuItem->ProgType = oldProgType;
  2713.                     strcpy( menuItem->ItemName, oldItemName );
  2714.                     strcpy( menuItem->Directory, oldDirectory );
  2715.                     strcpy( menuItem->ActionToDo, oldAction );
  2716.                     strcpy( menuItem->CmdLnArgs, oldCmdLn );
  2717.                     WinDismissDlg( hWnd, TRUE );
  2718.                     return 0;
  2719.                     }
  2720.                 //--------------------------------------------------------------
  2721.                 // user pressed OK, save current information for this item
  2722.                 //--------------------------------------------------------------
  2723.                 case DID_OK: {
  2724.                     // save program type and max/min startup status
  2725.                     USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2726.                     menuItem->ProgType = 0;
  2727.                     if (WinQueryButtonCheckstate( hWnd, FOLDER ))
  2728.                         menuItem->ProgType = WPSFOLDER;
  2729.                     if (WinQueryButtonCheckstate( hWnd, OS2WIN ))
  2730.                         menuItem->ProgType = OS2 + WINDOWED;
  2731.                     if (WinQueryButtonCheckstate( hWnd, OS2FS ))
  2732.                         menuItem->ProgType = OS2 + FULLSCREEN;
  2733.                     if (WinQueryButtonCheckstate( hWnd, DOSWIN ))
  2734.                         menuItem->ProgType = DOS + WINDOWED;
  2735.                     if (WinQueryButtonCheckstate( hWnd, DOSFS ))
  2736.                         menuItem->ProgType = DOS + FULLSCREEN;
  2737.                     if (WinQueryButtonCheckstate( hWnd, WINOS2WIN ))
  2738.                         menuItem->ProgType = WINOS2 + WINDOWED;
  2739.                     if (WinQueryButtonCheckstate( hWnd, WINOS2FS ))
  2740.                         menuItem->ProgType = WINOS2 + FULLSCREEN;
  2741.                     if (WinQueryButtonCheckstate( hWnd, PMAPP ))
  2742.                         menuItem->ProgType = PM;
  2743.                     if (WinQueryButtonCheckstate( hWnd, MAXIMIZED ))
  2744.                         menuItem->ProgType = menuItem->ProgType | STARTMAX;
  2745.                     if (WinQueryButtonCheckstate( hWnd, MINIMIZED ))
  2746.                         menuItem->ProgType = menuItem->ProgType | STARTMIN;
  2747.                     if (WinQueryButtonCheckstate( hWnd, STARTWPS ))
  2748.                         menuItem->ProgType = menuItem->ProgType | STARTASWPS;
  2749.  
  2750.                     // save name, path, directory, command line args
  2751.                     WinQueryDlgItemText( hWnd, ITEMNAME, MAXITEMNAMELENGTH,
  2752.                                          menuItem->ItemName);
  2753.                     WinQueryDlgItemText( hWnd, PATHNAME, MAXACTIONSTRINGLENGTH,
  2754.                                          menuItem->ActionToDo);
  2755.                     WinQueryDlgItemText( hWnd, ARGUMENTS, MAXARGSTRINGLENGTH,
  2756.                                          menuItem->CmdLnArgs);
  2757.                     WinQueryDlgItemText( hWnd, DIRECTORY, MAXDIRSTRINGLENGTH,
  2758.                                          menuItem->Directory);
  2759.                     WinDismissDlg( hWnd, TRUE );
  2760.                     return 0;
  2761.                     }
  2762.             default:
  2763.                 return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2764.             }
  2765.         }
  2766.         //----------------------------------------------------------------------
  2767.         // if nothing further we want to intercept, pass message onto system
  2768.         //----------------------------------------------------------------------
  2769.         default:
  2770.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2771.     }
  2772. }
  2773.  
  2774.  
  2775. ////////////////////////////////////////////////////////////////////////////////
  2776. // AddAnItemProc - the message handler for the "add an item to a menu" dialog
  2777. ////////////////////////////////////////////////////////////////////////////////
  2778. MRESULT EXPENTRY AddAnItemProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  2779. {
  2780.    switch( msg )
  2781.     {
  2782.         //----------------------------------------------------------------------
  2783.         // when the dialog is being initialized, center it on desktop and put
  2784.         // the current data into control fields
  2785.         //----------------------------------------------------------------------
  2786.         case WM_INITDLG: {
  2787.             SWP swp;
  2788.             WinSendDlgItemMsg( hWnd, ITEMNAME, EM_SETTEXTLIMIT,
  2789.                                MPFROM2SHORT( MAXITEMNAMELENGTH-1, 0 ), 0 );
  2790.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  2791.             WinSetWindowPos( hWnd, (HWND)0,
  2792.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  2793.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  2794.                              0, 0, SWP_MOVE);
  2795.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2796.             }
  2797.         //----------------------------------------------------------------------
  2798.         // process a command message received from the system
  2799.         //----------------------------------------------------------------------
  2800.         case WM_COMMAND:
  2801.         {
  2802.             USHORT command = SHORT1FROMMP(mp1);
  2803.             switch( command )
  2804.                 {
  2805.                 //--------------------------------------------------------------
  2806.                 // if they pressed OK, then save the data in the dialog as an
  2807.                 // item that we can now launch from the fileBar.
  2808.                 //--------------------------------------------------------------
  2809.                 case DID_OK: {
  2810.                     Menus[MenuSelection][ (NumItems[MenuSelection]) ] = new USERMENUITEM;
  2811.                     USERMENUITEM* menuItem = Menus[MenuSelection][ (NumItems[MenuSelection]) ];
  2812.                     WinQueryDlgItemText( hWnd, ITEMNAME, MAXMENUNAMELENGTH, menuItem->ItemName );
  2813.                     menuItem->ActionToDo[0] = '\0';
  2814.                     menuItem->CmdLnArgs[0] = '\0';
  2815.                     menuItem->Directory[0] = '\0';
  2816.                     menuItem->ProgType = PM;
  2817.                     WinDismissDlg( hWnd, TRUE );
  2818.                     ItemSelection = NumItems[MenuSelection];
  2819.                     NumItems[MenuSelection]++;
  2820.                     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, FALSE,
  2821.                                       allowPopUpMenu, popUpMessageID );
  2822.                     WinDlgBox(HWND_DESKTOP,
  2823.                               hWnd,
  2824.                               (PFNWP)EditItemDataProc,
  2825.                               0,
  2826.                               EDITITEMDATA,
  2827.                               (PVOID)NULL);
  2828.                     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  2829.                                       allowPopUpMenu, popUpMessageID );
  2830.                     return 0;
  2831.                     }
  2832.                 //--------------------------------------------------------------
  2833.                 // if they pressed cancel, save no data and return
  2834.                 //--------------------------------------------------------------
  2835.                 case DID_CANCEL: {
  2836.                     WinDismissDlg( hWnd, TRUE );
  2837.                     return 0;
  2838.                     }
  2839.                 //--------------------------------------------------------------
  2840.                 // nothing further we care about, pass on for default processing
  2841.                 //--------------------------------------------------------------
  2842.                 default:
  2843.                     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2844.                 }
  2845.         }
  2846.         //----------------------------------------------------------------------
  2847.         // if nothing further we want to intercept, pass message onto system
  2848.         //----------------------------------------------------------------------
  2849.         default:
  2850.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2851.     }
  2852. }
  2853.  
  2854.  
  2855. ////////////////////////////////////////////////////////////////////////////////
  2856. // Message handler for entering a runtime parameter
  2857. ////////////////////////////////////////////////////////////////////////////////
  2858. MRESULT EXPENTRY EnterParamProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  2859. {
  2860.    switch( msg )
  2861.     {
  2862.         //----------------------------------------------------------------------
  2863.         // when the dialog is being initialized, center it on desktop
  2864.         //----------------------------------------------------------------------
  2865.         case WM_INITDLG: {
  2866.             SWP swp;
  2867.  
  2868.             WinSetWindowText( hWnd, parameterTitle );
  2869.             WinSetDlgItemText( hWnd, PARAMETER_TEXT, ParameterTextPtr );
  2870.             WinSendDlgItemMsg( hWnd, PARAMETER_TEXT, EM_SETTEXTLIMIT, MPFROMSHORT( sizeof(variableText) ), 0 );
  2871.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  2872.             WinSetWindowPos( hWnd, (HWND)0,
  2873.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  2874.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  2875.                              0, 0, SWP_MOVE);
  2876.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2877.             }
  2878.         //----------------------------------------------------------------------
  2879.         // if we receive any system message, dismiss the dialog box
  2880.         //----------------------------------------------------------------------
  2881.         case WM_COMMAND:
  2882.         {
  2883.             WinQueryDlgItemText( hWnd, PARAMETER_EDIT, sizeof(variableText), (PSZ)variableText );
  2884.             WinDismissDlg( hWnd, TRUE );
  2885.             return 0;
  2886.         }
  2887.         //----------------------------------------------------------------------
  2888.         // if nothing further we want to intercept, pass message onto system
  2889.         //----------------------------------------------------------------------
  2890.         default:
  2891.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2892.     }
  2893. }
  2894.  
  2895.  
  2896. ////////////////////////////////////////////////////////////////////////////////
  2897. // gives a newly start application the input focus
  2898. ////////////////////////////////////////////////////////////////////////////////
  2899. void giveApplicationFocus( void )
  2900. {
  2901.     SHORT i,h;
  2902.     PSWBLOCK SwitchBlockPtr;
  2903.     ULONG numItems = WinQuerySwitchList( hab, NULL, 0 );
  2904.     ULONG Buffer;
  2905.     SHORT count = 0;
  2906.  
  2907.     while ((numItems == oldNumItems) && (++count < MAXCOUNT)) {
  2908.         DosSleep(10);
  2909.         numItems = WinQuerySwitchList( hab, NULL, 0 );
  2910.         }
  2911.  
  2912.     Buffer = (numItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
  2913.     PVOID my = new BYTE[Buffer];
  2914.     WinQuerySwitchList( hab, (SWBLOCK*)my, Buffer );
  2915.     SwitchBlockPtr = (PSWBLOCK)(my);
  2916.  
  2917.     for (i=0; i<numItems; i++)
  2918.         for (h=0; h<oldNumItems; h++)
  2919.            if ( SwitchBlockPtr->aswentry[i].swctl.hwnd == oldTaskHandles[h])
  2920.                 SwitchBlockPtr->aswentry[i].swctl.hwnd = NULLHANDLE;
  2921.  
  2922.     i = 0;
  2923.     while (SwitchBlockPtr->aswentry[i].swctl.hwnd == NULLHANDLE)
  2924.         i++;
  2925.     WinFocusChange( HWND_DESKTOP, hwndFrame, 0 );
  2926.     WinSwitchToProgram( SwitchBlockPtr->aswentry[i].hswitch );
  2927. }
  2928.  
  2929.  
  2930. ////////////////////////////////////////////////////////////////////////////////
  2931. // startApplication uses DosStartSession to start a batch file to start an
  2932. // application pointed to in one of the user menus by menu and item variables.
  2933. ////////////////////////////////////////////////////////////////////////////////
  2934. SHORT startApplication( SHORT menu, SHORT item )
  2935. {
  2936.     APIRET rc;
  2937.     STARTDATA startData;
  2938.     ULONG sessionId;
  2939.     PID ppId;
  2940.     UCHAR ObjBuf[2];
  2941.     SHORT i;
  2942.     SHORT h;
  2943.     PSWBLOCK SwitchBlockPtr;
  2944.     ULONG oldBuffer;
  2945.     CHAR parameters[MAXARGSTRINGLENGTH*3];
  2946.     CHAR SettingsBuffer[WPSBUFFER];
  2947.     CHAR itemName[MAXITEMNAMELENGTH];
  2948.     USERMENUITEM* menuItem = Menus[menu][item];
  2949.  
  2950. /////////////////////////////////////////////////////////////////////////////////
  2951.     oldNumItems = WinQuerySwitchList( hab, NULL, 0 );
  2952.     oldBuffer = (oldNumItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
  2953.     PVOID myBuffer = new BYTE[oldBuffer];
  2954.     WinQuerySwitchList( hab, (SWBLOCK*)myBuffer, oldBuffer );
  2955.     SwitchBlockPtr = (PSWBLOCK)(myBuffer);
  2956.     for (i=0; i < oldNumItems; i++)
  2957.         oldTaskHandles[i] = SwitchBlockPtr->aswentry[i].swctl.hwnd;
  2958.     delete(myBuffer);
  2959. /////////////////////////////////////////////////////////////////////////////////
  2960.  
  2961.     i = 0;
  2962.     h = 0;
  2963.     // remove tilde from title window
  2964.  
  2965.     while (menuItem->ItemName[i]!='\0') {
  2966.         if (menuItem->ItemName[i]!='~')
  2967.             itemName[h++] = menuItem->ItemName[i];
  2968.         i++;
  2969.         }
  2970.     itemName[h] = 0;
  2971.  
  2972.     // get command line arguments via user input if necessary
  2973.     i = 0;
  2974.     h = 0;
  2975.     while ( menuItem->CmdLnArgs[i] != 0 ) {
  2976.         if (menuItem->CmdLnArgs[i] == STARTINPUT) {
  2977.             short j = 0;
  2978.             CHAR tmp[MAXARGSTRINGLENGTH];
  2979.  
  2980.             i++;
  2981.             while ( (menuItem->CmdLnArgs[i] != 0) &&
  2982.                     (menuItem->CmdLnArgs[i] != ENDINPUT ))
  2983.                 tmp[j++] = menuItem->CmdLnArgs[i++];
  2984.             tmp[j] = 0;
  2985.  
  2986.             if (menuItem->CmdLnArgs[i] != 0)
  2987.                 i++;
  2988.  
  2989.             {
  2990.                 CHAR mesg[18+MAXARGSTRINGLENGTH];
  2991.                 SHORT k = 0;
  2992.  
  2993.                 sprintf( parameterTitle, "%s parameter...", menuItem->ItemName );
  2994.                 sprintf( mesg, "Please enter '%s'", tmp);
  2995.                 ParameterTextPtr = mesg;
  2996.                 (VOID*)WinDlgBox(HWND_DESKTOP,
  2997.                                  hwndFrame,
  2998.                                  (PFNWP)EnterParamProc,
  2999.                                  0,
  3000.                                  ENTERPARAMETER,
  3001.                                  (PVOID)NULL);
  3002.  
  3003.                 while ( variableText[k] != '\0')
  3004.                     parameters[h++] = variableText[k++];
  3005.             }
  3006.  
  3007.             }
  3008.         else
  3009.             parameters[h++] = menuItem->CmdLnArgs[i++];
  3010.         }
  3011.     parameters[h] = '\0';
  3012.  
  3013.     //--------------------------------------------------------------------------
  3014.     // open a WPS folder/object
  3015.     //--------------------------------------------------------------------------
  3016.     if ((menuItem->ProgType & WPSFOLDER) || (menuItem->ProgType & STARTASWPS)) {
  3017.         CHAR string[MAXACTIONSTRINGLENGTH+MAXDIRSTRINGLENGTH+2];
  3018.         HOBJECT object;
  3019.  
  3020.         if (menuItem->ProgType & WPSFOLDER)
  3021.             sprintf(string, "%s%s\0", menuItem->Directory,menuItem->ActionToDo);
  3022.         else
  3023.             sprintf(string, "%s\0", menuItem->ActionToDo);
  3024.  
  3025.         object = WinQueryObject( string );
  3026.         if (object==NULLHANDLE) {
  3027.             CHAR errorText[] = "FileBar Error!";
  3028.  
  3029.             if (FileBarIsShell)
  3030.                 WinMessageBox( HWND_DESKTOP, hwndFrame, "Could not locate the specified WPS object!\n\nRemember!  WPS objects are not accessible if FileBar is used as WPS replacement!", errorText, 0,
  3031.                                MB_MOVEABLE|MB_OK|MB_ERROR);
  3032.             else WinMessageBox( HWND_DESKTOP, hwndFrame, "Could not locate the specified WPS object!\n\nThe pathname and/or directory you specified may not be correct.", errorText, 0,
  3033.                                 MB_MOVEABLE|MB_OK|MB_ERROR);
  3034.             return 0;
  3035.             }
  3036.  
  3037.         WinSetObjectData(object, "OPEN=DEFAULT");
  3038.  
  3039.         giveApplicationFocus();
  3040.         return 0;
  3041.         }
  3042.  
  3043.  
  3044.     //--------------------------------------------------------------------------
  3045.     // this launches a command shell (DOS or OS2 (Windowed or FS session))
  3046.     //--------------------------------------------------------------------------
  3047.     if ((menuItem->ActionToDo[0] == '\0') && !(menuItem->ProgType & WINOS2)) {
  3048.         ULONG currentDrive;
  3049.         ULONG driveMap;
  3050.         CHAR InputDir[MAXPATH + 9];
  3051.  
  3052.         DosQueryCurrentDisk( ¤tDrive, &driveMap );
  3053.         DosSetDefaultDisk( (ULONG)(toupper(menuItem->Directory[0])-'A' + 1) );
  3054.  
  3055.         memset( &startData, 0, sizeof(STARTDATA) );
  3056.         startData.Related = SSF_RELATED_INDEPENDENT;
  3057.         startData.FgBg = SSF_FGBG_FORE;
  3058.         startData.TraceOpt = SSF_TRACEOPT_NONE;
  3059.         startData.InheritOpt = SSF_INHERTOPT_PARENT;
  3060.         startData.ObjectBuffer = ObjBuf;
  3061.         startData.ObjectBuffLen = sizeof(ObjBuf);
  3062.         startData.Length = sizeof(startData);
  3063.         startData.PgmTitle = itemName;
  3064.         strcpy( InputDir, "/K cd  \0");
  3065.         strcpy( InputDir+6, menuItem->Directory );
  3066.         startData.PgmInputs = InputDir;
  3067.  
  3068.         startData.PgmControl = SSF_CONTROL_VISIBLE;
  3069.         if (menuItem->ProgType & MAXIMIZED)
  3070.             startData.PgmControl = SSF_CONTROL_VISIBLE | SSF_CONTROL_MAXIMIZE;
  3071.         else if (menuItem->ProgType & MINIMIZED)
  3072.             startData.PgmControl = SSF_CONTROL_VISIBLE | SSF_CONTROL_MINIMIZE;
  3073.  
  3074.         if (menuItem->ProgType & DOS) {
  3075.             if (menuItem->ProgType & WINDOWED)
  3076.                 startData.SessionType = SSF_TYPE_WINDOWEDVDM;
  3077.             else
  3078.                 startData.SessionType = SSF_TYPE_VDM;
  3079.             rc = DosStartSession( (STARTDATA*) &startData, (ULONG*)&sessionId,
  3080.                                   (PID*) &ppId );
  3081.  
  3082.             DosSetDefaultDisk( currentDrive );
  3083.             giveApplicationFocus();
  3084.             return 0;
  3085.             }
  3086.         else if (menuItem->ProgType & OS2) {
  3087.             if (menuItem->ProgType & WINDOWED)
  3088.                 startData.SessionType = SSF_TYPE_WINDOWABLEVIO;
  3089.             else
  3090.                 startData.SessionType = SSF_TYPE_FULLSCREEN;
  3091.             rc = DosStartSession( (STARTDATA*) &startData, (ULONG*)&sessionId,
  3092.                                   (PID*) &ppId );
  3093.  
  3094.             DosSetDefaultDisk( currentDrive );
  3095.             giveApplicationFocus();
  3096.             return 0;
  3097.             }
  3098.         WinMessageBox( HWND_DESKTOP, hwndFrame, "Error opening command shell!", NULL, 0,
  3099.                        MB_MOVEABLE|MB_ERROR|MB_OK);
  3100.  
  3101.         return 0;
  3102.         }
  3103.  
  3104.     //--------------------------------------------------------------------------
  3105.     // this section of code launches a program (non-command shell application)
  3106.     //--------------------------------------------------------------------------
  3107.     {
  3108.     ULONG currentDrive;
  3109.     ULONG driveMap;
  3110.     UCHAR defaultDirectory[MAXPATH];
  3111.     CHAR inputs[1024];
  3112.  
  3113.     memset( &startData, 0, sizeof(STARTDATA) );
  3114.     startData.Length = sizeof(STARTDATA);
  3115.     startData.Related = SSF_RELATED_INDEPENDENT;
  3116.     startData.FgBg = SSF_FGBG_FORE;
  3117.     startData.TraceOpt = SSF_TRACEOPT_NONE;
  3118.     startData.PgmTitle = itemName;
  3119.     startData.InheritOpt = SSF_INHERTOPT_PARENT;
  3120.     startData.SessionType = SSF_TYPE_WINDOWABLEVIO;
  3121.     startData.PgmControl = SSF_CONTROL_VISIBLE;
  3122.     startData.SessionType = SSF_TYPE_PM;
  3123.     startData.PgmName = menuItem->ActionToDo;
  3124.     startData.PgmInputs = parameters;
  3125.  
  3126.     if (menuItem->ProgType & DOS) {
  3127.         if (menuItem->ProgType & FULLSCREEN)
  3128.             startData.SessionType = SSF_TYPE_VDM;
  3129.         else if (menuItem->ProgType & WINDOWED)
  3130.             startData.SessionType = SSF_TYPE_WINDOWEDVDM;
  3131.         }
  3132.     else if (menuItem->ProgType & OS2) {
  3133.         if (menuItem->ProgType & FULLSCREEN)
  3134.             startData.SessionType = SSF_TYPE_FULLSCREEN;
  3135.         else if (menuItem->ProgType & WINDOWED)
  3136.             startData.SessionType = SSF_TYPE_WINDOWABLEVIO;
  3137.         }
  3138.  
  3139.     else if (menuItem->ProgType & WINOS2) {
  3140.         if (menuItem->ProgType & FULLSCREEN)
  3141.             startData.SessionType = SSF_TYPE_FULLSCREEN;
  3142.         else if (menuItem->ProgType & WINDOWED)
  3143.            startData.SessionType = 18;               //PROG_31_ENHSEAMLESSCOMMON
  3144.         if (menuItem->ActionToDo[0])
  3145.             sprintf( inputs, "/c winos2 %s %s", menuItem->ActionToDo, parameters );
  3146.         else
  3147.             sprintf( inputs, "/c winos2 %s", parameters );
  3148.         startData.PgmInputs = inputs;
  3149.         startData.PgmName = 0;
  3150.         }
  3151.  
  3152.     if (menuItem->ProgType & STARTMAX)
  3153.         startData.PgmControl |= SSF_CONTROL_MAXIMIZE;
  3154.     else if (menuItem->ProgType & STARTMIN)
  3155.         startData.PgmControl |= SSF_CONTROL_MINIMIZE;
  3156.  
  3157.     if (!(menuItem->ProgType & WINOS2) && (startData.PgmName != NULL) && (startData.SessionType != SSF_TYPE_PM)) {
  3158.         CHAR temp[MAXPATH+MAXARGSTRINGLENGTH+6];
  3159.         sprintf(temp, "/c %s %s\0", menuItem->ActionToDo, parameters);
  3160.         startData.PgmName = 0;
  3161.         strcpy(inputs, temp);
  3162.         startData.PgmInputs = inputs;
  3163.         }
  3164.  
  3165.     // save current drive and directory
  3166.     DosQueryCurrentDisk( ¤tDrive, &driveMap );
  3167.     {
  3168.         CHAR temp[MAXPATH+5];
  3169.         ULONG tempSize = MAXPATH;
  3170.         defaultDirectory[0]= (currentDrive+'A'-1);
  3171.         defaultDirectory[1]= ':';
  3172.         defaultDirectory[2]= '\\';
  3173.         defaultDirectory[3]= '\0';
  3174.         DosQueryCurrentDir( currentDrive, (CHAR*)&temp, &tempSize );
  3175.         strcat( defaultDirectory, temp );
  3176.     }
  3177.  
  3178.     // point to working directory of program to execute
  3179.     if (((toupper(menuItem->Directory[0]))>='A') && ((toupper(menuItem->Directory[0]))<='Z'))
  3180.         DosSetDefaultDisk( (ULONG)(toupper(menuItem->Directory[0])-'A' + 1) );
  3181.     DosSetCurrentDir( menuItem->Directory );
  3182.  
  3183.  
  3184.     // try and locate a settings file
  3185.     {
  3186.     FILE *FileHandle;
  3187.  
  3188.     memset( &SettingsBuffer, 0, sizeof(SettingsBuffer) );
  3189.     if ((FileHandle = fopen("SETTINGS.INI","rt")) != NULL) {
  3190.         SHORT offset = 0;
  3191.         CHAR ch;
  3192.  
  3193.         while (fscanf(FileHandle, "%c", &ch) != EOF) {
  3194.             if ( ch == '\n' )
  3195.                 SettingsBuffer[ offset++ ] = '\0';
  3196.             else
  3197.                 if ( ch != '\r' )
  3198.                     SettingsBuffer[ offset++ ] = ch;
  3199.             }
  3200.         SettingsBuffer[ offset++ ] = '\0';
  3201.         SettingsBuffer[ offset++ ] = '\0';
  3202.         fclose(FileHandle);
  3203.         startData.Environment = SettingsBuffer;
  3204.         }
  3205.  
  3206.     }
  3207.  
  3208.     // launch application
  3209.     rc = DosStartSession( (STARTDATA*) &startData, (ULONG*)&sessionId,
  3210.                           (PID*) &ppId );
  3211.  
  3212.     // restore current drive and directory
  3213.     DosSetDefaultDisk( currentDrive );
  3214.     DosSetCurrentDir( defaultDirectory );
  3215.  
  3216.     if ((rc != 0) && (rc != ERROR_SMG_START_IN_BACKGROUND) && (!startUp)) {
  3217.         char text[] = "Could not open the specified item.  Path and directory information may not be correct.";
  3218.         char title[28];
  3219.  
  3220.         sprintf(title, "FileBar Error code #%d", rc );
  3221.         WinMessageBox( HWND_DESKTOP, hwndFrame, text, title, 0,
  3222.                        MB_MOVEABLE|MB_ERROR|MB_OK);
  3223.         return 0;
  3224.         }
  3225.  
  3226.     giveApplicationFocus();
  3227.     return 0;
  3228.     }
  3229. }
  3230.  
  3231.  
  3232. ////////////////////////////////////////////////////////////////////////////////
  3233. // display a background bitmap
  3234. ////////////////////////////////////////////////////////////////////////////////
  3235. VOID displayBackground( VOID )
  3236. {
  3237.     DESKTOP desktop;
  3238.  
  3239.     if ((!FileBarIsShell) && (showBackground))
  3240.         WinMessageBox( HWND_DESKTOP, hwndFrame, "The background bitmap could not be displayed since FileBar is not currently acting as the shell.", "FileBar - Display Background", 0,
  3241.                        MB_MOVEABLE|MB_ERROR|MB_OK);
  3242.     else if ((showBackground) || (isBackgroundDisplayed)) {
  3243.         desktop.cbSize = sizeof( DESKTOP );
  3244.         desktop.hbm = 0;
  3245.         desktop.x = 0;
  3246.         desktop.y = 0;
  3247.         desktop.fl = SDT_DESTROY;
  3248.         if (isBackgroundDisplayed)
  3249.             WinSetDesktopBkgnd( HWND_DESKTOP, &desktop );
  3250.  
  3251.         desktop.fl = SDT_LOADFILE|SDT_CENTER;
  3252.         if (backgroundAttr & SCALED)
  3253.             desktop.fl = SDT_SCALE|SDT_LOADFILE;
  3254.         if (backgroundAttr & TILED) {
  3255.             desktop.fl = SDT_TILE|SDT_LOADFILE;
  3256.             desktop.lTileCount = backgroundAttr - TILED;
  3257.             }
  3258.         strcpy( desktop.szFile, backgroundBitmap );
  3259.         if (showBackground) {
  3260.             WinSetDesktopBkgnd( HWND_DESKTOP, &desktop );
  3261.             isBackgroundDisplayed = TRUE;
  3262.             }
  3263.         }
  3264. }
  3265.  
  3266.  
  3267. ////////////////////////////////////////////////////////////////////////////////
  3268. // Message handler for a generic information-only dialog box (help & prod info)
  3269. ////////////////////////////////////////////////////////////////////////////////
  3270. MRESULT EXPENTRY backgroundProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  3271. {
  3272.    switch( msg )
  3273.     {
  3274.         //----------------------------------------------------------------------
  3275.         // when the dialog is being initialized, center it on desktop
  3276.         //----------------------------------------------------------------------
  3277.         case WM_INITDLG: {
  3278.             SWP swp;
  3279.             char temp[12];
  3280.  
  3281.             WinCheckButton( hWnd, BKGND_NORMAL, TRUE );
  3282.             if (backgroundAttr & SCALED)
  3283.                 WinCheckButton( hWnd, BKGND_SCALED, TRUE );
  3284.             else if (backgroundAttr & TILED) {
  3285.                 WinCheckButton( hWnd, BKGND_TILED, TRUE );
  3286.                 WinEnableControl( hWnd, BKGND_TILENUMBER, TRUE );
  3287.                 WinEnableControl( hWnd, BKGND_TILENUMBERTEXT, TRUE );
  3288.                 WinEnableControl( hWnd, BKGND_LESS, TRUE );
  3289.                 WinEnableControl( hWnd, BKGND_MORE, TRUE );
  3290.                 }
  3291.  
  3292.             if (backgroundAttr & SCALED)
  3293.                 backgroundAttr = backgroundAttr - SCALED;
  3294.             if (backgroundAttr & TILED)
  3295.                 backgroundAttr = backgroundAttr - TILED;
  3296.  
  3297.             sprintf(temp,"%d x %d", backgroundAttr, backgroundAttr);
  3298.             WinSetDlgItemText( hWnd, BKGND_TILENUMBER, temp );
  3299.  
  3300.             WinSendDlgItemMsg( hWnd, BKGND_BITMAPNAME, EM_SETTEXTLIMIT, MPFROMSHORT( sizeof(backgroundBitmap) ), 0 );
  3301.             WinSetDlgItemText( hWnd, BKGND_BITMAPNAME, backgroundBitmap );
  3302.  
  3303.             WinCheckButton( hWnd, BKGND_SHOW, showBackground );
  3304.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  3305.             WinSetWindowPos( hWnd, (HWND)0,
  3306.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  3307.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  3308.                              0, 0, SWP_MOVE);
  3309.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3310.             }
  3311.         //----------------------------------------------------------------------
  3312.         //----------------------------------------------------------------------
  3313.         case WM_CONTROL:
  3314.         {
  3315.             if (SHORT2FROMMP(mp1)==BN_CLICKED) {
  3316.                 BOOLEAN option = FALSE;
  3317.                 if (WinQueryButtonCheckstate( hWnd, BKGND_TILED))
  3318.                     option = TRUE;
  3319.                 WinEnableControl( hWnd, BKGND_TILENUMBER, option );
  3320.                 WinEnableControl( hWnd, BKGND_TILENUMBERTEXT, option );
  3321.                 WinEnableControl( hWnd, BKGND_LESS, option );
  3322.                 WinEnableControl( hWnd, BKGND_MORE, option );
  3323.                 }
  3324.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3325.         }
  3326.         //----------------------------------------------------------------------
  3327.         //----------------------------------------------------------------------
  3328.         case WM_COMMAND:
  3329.         {
  3330.             USHORT command = SHORT1FROMMP(mp1);
  3331.             switch( command )
  3332.                 {
  3333.                 //--------------------------------------------------------------
  3334.                 // if they pressed OK, then save the data in the dialog as an
  3335.                 // item that we can now launch from the fileBar.
  3336.                 //--------------------------------------------------------------
  3337.                 case DID_OK: {
  3338.                     WinQueryDlgItemText( hWnd, BKGND_BITMAPNAME, sizeof(backgroundBitmap), (PSZ)backgroundBitmap );
  3339.                     showBackground = WinQueryButtonCheckstate( hWnd, BKGND_SHOW );
  3340.                     if (WinQueryButtonCheckstate( hWnd, BKGND_SCALED))
  3341.                         backgroundAttr = backgroundAttr + SCALED;
  3342.                     if (WinQueryButtonCheckstate( hWnd, BKGND_TILED))
  3343.                         backgroundAttr = backgroundAttr + TILED;
  3344.                     WinDismissDlg( hWnd, TRUE );
  3345.                     return 0;
  3346.                     }
  3347.                 //--------------------------------------------------------------
  3348.                 //--------------------------------------------------------------
  3349.                 case BKGND_LESS: {
  3350.                     char temp[12];
  3351.  
  3352.                     if (backgroundAttr > 1)
  3353.                         backgroundAttr--;
  3354.                     sprintf(temp,"%d x %d", backgroundAttr, backgroundAttr);
  3355.                     WinSetDlgItemText( hWnd, BKGND_TILENUMBER, temp );
  3356.                     return 0;
  3357.                     }
  3358.                 //--------------------------------------------------------------
  3359.                 //--------------------------------------------------------------
  3360.                 case BKGND_MORE: {
  3361.                     char temp[12];
  3362.  
  3363.                     if (backgroundAttr < 32)
  3364.                         backgroundAttr++;
  3365.                     sprintf(temp,"%d x %d", backgroundAttr, backgroundAttr);
  3366.                     WinSetDlgItemText( hWnd, BKGND_TILENUMBER, temp );
  3367.                     return 0;
  3368.                     }
  3369.                 //--------------------------------------------------------------
  3370.                 //--------------------------------------------------------------
  3371.                 case BKGND_FINDFILE: {
  3372.                     CHAR title[] = "FileBar - Find A Background Image";
  3373.                     HWND hwndDialog;
  3374.                     CHAR oldDir[MAXPATH];
  3375.  
  3376.                     fileDlgInfo.fl = FDS_OPEN_DIALOG|FDS_CENTER;
  3377.                     fileDlgInfo.pszTitle = title;
  3378.                     strcpy( oldDir, fileDlgInfo.szFullFile );
  3379.                     strcat(fileDlgInfo.szFullFile, "*.BMP\0");
  3380.  
  3381.                     hwndDialog = WinFileDlg( HWND_DESKTOP, hWnd, &fileDlgInfo );
  3382.                     if (hwndDialog && (fileDlgInfo.lReturn == DID_OK)) {
  3383.                         strcpy( backgroundBitmap, fileDlgInfo.szFullFile );
  3384.                         resetFileDialog();
  3385.                         WinSetDlgItemText( hWnd, BKGND_BITMAPNAME, backgroundBitmap );
  3386.  
  3387.                         /*
  3388.                         s=0;
  3389.                         while(fileDlgInfo.szFullFile[s]!='\0')
  3390.                             s++;
  3391.                         while((fileDlgInfo.szFullFile[s]!='\\') && (s>=0))
  3392.                             s--;
  3393.  
  3394.                         if (fileDlgInfo.szFullFile[s]=='\\')
  3395.                             fileDlgInfo.szFullFile[s+1]='\0';
  3396.                         else
  3397.                             fileDlgInfo.szFullFile[0]='\0';
  3398.                         */
  3399.                         }
  3400.                     else
  3401.                         strcpy( fileDlgInfo.szFullFile, oldDir );
  3402.                     return 0;
  3403.                     }
  3404.             }
  3405.         }
  3406.         //----------------------------------------------------------------------
  3407.         // if nothing further we want to intercept, pass message onto system
  3408.         //----------------------------------------------------------------------
  3409.         default:
  3410.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3411.     }
  3412. }
  3413.  
  3414.  
  3415. ////////////////////////////////////////////////////////////////////////////////
  3416. // Message handler for a generic information-only dialog box (help & prod info)
  3417. ////////////////////////////////////////////////////////////////////////////////
  3418. MRESULT EXPENTRY startupProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  3419. {
  3420.    switch( msg )
  3421.     {
  3422.         //----------------------------------------------------------------------
  3423.         // when the dialog is being initialized, center it on desktop
  3424.         //----------------------------------------------------------------------
  3425.         case WM_INITDLG: {
  3426.             SWP swp;
  3427.             short i,j;
  3428.             char temp[MAXITEMNAMELENGTH+8];
  3429.  
  3430.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  3431.             WinSetWindowPos( hWnd, (HWND)0,
  3432.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  3433.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  3434.                              0, 0, SWP_MOVE);
  3435.             WinSendDlgItemMsg( hWnd, STARTUP_ITEMLIST, LM_DELETEALL, 0, 0);
  3436.             temp[0] = ' ';
  3437.             temp[1] = ' ';
  3438.             temp[2] = '-';
  3439.             temp[3] = ' ';
  3440.             for (i=0; i<NumMenus; i++) {
  3441.                 WinSendDlgItemMsg( hWnd, STARTUP_ITEMLIST, LM_INSERTITEM, MPFROMSHORT( LIT_END ), MenuName[i] );
  3442.                 for (j=0; j<NumItems[i]; j++)
  3443.                     if (Menus[i][j]->ItemName[0] != '\0') {
  3444.                         temp[4] = '\0';
  3445.                         strcat(temp, Menus[i][j]->ItemName);
  3446.                         WinSendDlgItemMsg( hWnd, STARTUP_ITEMLIST, LM_INSERTITEM, MPFROMSHORT( LIT_END ), temp );
  3447.                         }
  3448.                 }
  3449.  
  3450.             WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_DELETEALL, 0, 0);
  3451.             for( i = 0; i< numStartItems; i++)
  3452.                 WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_INSERTITEM, MPFROMSHORT( LIT_END ), Menus[(StartUpMenu[i])][(StartUpItem[i])]->ItemName );
  3453.  
  3454.             WinCheckButton( hWnd, STARTUP_LAUNCH, DoStartUpList );
  3455.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3456.             }
  3457.         //----------------------------------------------------------------------
  3458.         //----------------------------------------------------------------------
  3459.         case WM_CONTROL:
  3460.         {
  3461.             if (SHORT2FROMMP(mp1)==BN_CLICKED) {
  3462.                 BOOLEAN option = FALSE;
  3463.                 if (WinQueryButtonCheckstate( hWnd, BKGND_TILED))
  3464.                     option = TRUE;
  3465.                 WinEnableControl( hWnd, BKGND_TILENUMBER, option );
  3466.                 WinEnableControl( hWnd, BKGND_TILENUMBERTEXT, option );
  3467.                 WinEnableControl( hWnd, BKGND_LESS, option );
  3468.                 WinEnableControl( hWnd, BKGND_MORE, option );
  3469.                 }
  3470.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3471.         }
  3472.         //----------------------------------------------------------------------
  3473.         //----------------------------------------------------------------------
  3474.         case WM_COMMAND:
  3475.         {
  3476.             USHORT command = SHORT1FROMMP(mp1);
  3477.             switch( command )
  3478.                 {
  3479.                 //--------------------------------------------------------------
  3480.                 //--------------------------------------------------------------
  3481.                 case STARTUP_ADD: {
  3482.  
  3483.                     if (numStartItems == MAXSTARTITEMS)
  3484.                         WinMessageBox( HWND_DESKTOP, hwndFrame, "No room to add an additional task!", "Add a start up item", 0,
  3485.                                        MB_MOVEABLE|MB_ERROR|MB_OK);
  3486.                     else {
  3487.                         char buffer[MAXITEMNAMELENGTH + 8];
  3488.                         SHORT i,j;
  3489.                         BOOL found = FALSE;
  3490.                         SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, STARTUP_ITEMLIST,
  3491.                                                                               LM_QUERYSELECTION,
  3492.                                                                               MPFROM2SHORT( LIT_FIRST, 0 ),
  3493.                                                                               0 ) );
  3494.                         if (itemSelected == LIT_NONE) {
  3495.                             WinMessageBox( HWND_DESKTOP, hwndFrame, "You must first select an item to add!", "Add a start up item", 0,
  3496.                                            MB_MOVEABLE|MB_ERROR|MB_OK);
  3497.                             return 0;
  3498.                             }
  3499.  
  3500.                         for( i=0; i<NumMenus; i++)
  3501.                             for( j=0; j<NumItems[i]; j++) {
  3502.                                 SHORT1FROMMP( WinSendDlgItemMsg( hWnd, STARTUP_ITEMLIST,
  3503.                                                          LM_QUERYITEMTEXT,
  3504.                                                          MPFROM2SHORT( itemSelected, sizeof(buffer) ),
  3505.                                                          &buffer ) );
  3506.                                 if (strcmp(&(buffer[4]),Menus[i][j]->ItemName)==0) {
  3507.                                     StartUpMenu[ numStartItems ] = i;
  3508.                                     StartUpItem[ numStartItems ] = j;
  3509.                                     numStartItems++;
  3510.                                     WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_INSERTITEM, MPFROMSHORT( LIT_END ), Menus[i][j]->ItemName );
  3511.                                     found = TRUE;
  3512.                                     }
  3513.                                 }
  3514.  
  3515.                             if (!found)
  3516.                                 WinMessageBox( HWND_DESKTOP, hwndFrame, "You need to select an item -- not a menu!", "Add a start up item", 0,
  3517.                                                MB_MOVEABLE|MB_ERROR|MB_OK);
  3518.                         }
  3519.                     return 0;
  3520.                     }
  3521.                 //--------------------------------------------------------------
  3522.                 //--------------------------------------------------------------
  3523.                 case STARTUP_REMOVE: {
  3524.                     SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS,
  3525.                                                                      LM_QUERYSELECTION,
  3526.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  3527.                                                                      0 ) );
  3528.                     SHORT i;
  3529.  
  3530.                     if (itemSelected != LIT_NONE) {
  3531.                         for (i=itemSelected+1; i<numStartItems; i++) {
  3532.                             StartUpMenu[i-1] = StartUpMenu[i];
  3533.                             StartUpItem[i-1] = StartUpItem[i];
  3534.                             }
  3535.                         numStartItems--;
  3536.                         WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_DELETEALL, 0, 0);
  3537.                         for( i = 0; i< numStartItems; i++)
  3538.                             WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_INSERTITEM, MPFROMSHORT( LIT_END ), Menus[(StartUpMenu[i])][(StartUpItem[i])]->ItemName );
  3539.  
  3540.                         if (itemSelected == numStartItems)
  3541.                             WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_SELECTITEM,
  3542.                                                MPFROM2SHORT( numStartItems-1, 0 ),
  3543.                                                MPFROM2SHORT( TRUE, 0 ) );
  3544.                         else
  3545.                             WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_SELECTITEM,
  3546.                                                MPFROM2SHORT( itemSelected, 0 ),
  3547.                                                MPFROM2SHORT( TRUE, 0 ) );
  3548.                         }
  3549.  
  3550.                     return 0;
  3551.                     }
  3552.                 //--------------------------------------------------------------
  3553.                 //--------------------------------------------------------------
  3554.                 case STARTUP_CLEARALL: {
  3555.                     WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_DELETEALL, 0, 0);
  3556.                     numStartItems = 0;
  3557.                     return 0;
  3558.                     }
  3559.                 //--------------------------------------------------------------
  3560.                 //--------------------------------------------------------------
  3561.                 case STARTUP_MOVEDOWN: {
  3562.                     SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS,
  3563.                                                                      LM_QUERYSELECTION,
  3564.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  3565.                                                                      0 ) );
  3566.                     if ((itemSelected < (numStartItems-1)) && (itemSelected != LIT_NONE)) {
  3567.                         SHORT z;
  3568.                         SHORT i;
  3569.  
  3570.                         z = StartUpMenu[itemSelected+1];
  3571.                         StartUpMenu[itemSelected+1] = StartUpMenu[itemSelected];
  3572.                         StartUpMenu[itemSelected] = z;
  3573.  
  3574.                         z = StartUpItem[itemSelected+1];
  3575.                         StartUpItem[itemSelected+1] = StartUpItem[itemSelected];
  3576.                         StartUpItem[itemSelected] = z;
  3577.  
  3578.                         WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_DELETEALL, 0, 0);
  3579.                         for( i = 0; i< numStartItems; i++)
  3580.                             WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_INSERTITEM, MPFROMSHORT( LIT_END ), Menus[(StartUpMenu[i])][(StartUpItem[i])]->ItemName );
  3581.  
  3582.                         WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_SELECTITEM,
  3583.                                            MPFROM2SHORT( itemSelected+1, 0 ),
  3584.                                            MPFROM2SHORT( TRUE, 0 ) );
  3585.                         }
  3586.                     return 0;
  3587.                     }
  3588.                 //--------------------------------------------------------------
  3589.                 //--------------------------------------------------------------
  3590.                 case STARTUP_MOVEUP: {
  3591.                     SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS,
  3592.                                                                      LM_QUERYSELECTION,
  3593.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  3594.                                                                      0 ) );
  3595.                     if ((itemSelected > 0) && (itemSelected != LIT_NONE)) {
  3596.                         SHORT z;
  3597.                         SHORT i;
  3598.  
  3599.                         z = StartUpMenu[itemSelected-1];
  3600.                         StartUpMenu[itemSelected-1] = StartUpMenu[itemSelected];
  3601.                         StartUpMenu[itemSelected] = z;
  3602.  
  3603.                         z = StartUpItem[itemSelected-1];
  3604.                         StartUpItem[itemSelected-1] = StartUpItem[itemSelected];
  3605.                         StartUpItem[itemSelected] = z;
  3606.  
  3607.                         WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_DELETEALL, 0, 0);
  3608.                         for( i = 0; i< numStartItems; i++)
  3609.                             WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_INSERTITEM, MPFROMSHORT( LIT_END ), Menus[(StartUpMenu[i])][(StartUpItem[i])]->ItemName );
  3610.  
  3611.                         WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_SELECTITEM,
  3612.                                            MPFROM2SHORT( itemSelected-1, 0 ),
  3613.                                            MPFROM2SHORT( TRUE, 0 ) );
  3614.                         }
  3615.                     return 0;
  3616.                     }
  3617.                 //--------------------------------------------------------------
  3618.                 // if they pressed OK, then save the data in the dialog as an
  3619.                 // item that we can now launch from the fileBar.
  3620.                 //--------------------------------------------------------------
  3621.                 case DID_OK: {
  3622.                     DoStartUpList = WinQueryButtonCheckstate( hWnd, STARTUP_LAUNCH);
  3623.                     WinDismissDlg( hWnd, TRUE );
  3624.                     return 0;
  3625.                     }
  3626.             }
  3627.         }
  3628.         //----------------------------------------------------------------------
  3629.         // if nothing further we want to intercept, pass message onto system
  3630.         //----------------------------------------------------------------------
  3631.         default:
  3632.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3633.     }
  3634. }
  3635.  
  3636.  
  3637. ////////////////////////////////////////////////////////////////////////////////
  3638. // execute start up list of applications
  3639. ////////////////////////////////////////////////////////////////////////////////
  3640. VOID ExecuteStartUpList( VOID )
  3641. {
  3642.      SHORT i;
  3643.  
  3644.      if (DoStartUpList)
  3645.          for (i=0; i<numStartItems; i++)
  3646.              startApplication( StartUpMenu[i], StartUpItem[i] );
  3647.      startUp = FALSE;
  3648. }
  3649.  
  3650.  
  3651. ////////////////////////////////////////////////////////////////////////////////
  3652. // update the buttons of the calendar to reflect current month structure
  3653. ////////////////////////////////////////////////////////////////////////////////
  3654. VOID updateCalendar( HWND hWnd )
  3655. {
  3656.     LONG backgroundColor = CLR_YELLOW;
  3657.     LONG foregroundColor = CLR_BLACK;
  3658.     CHAR temp[50];
  3659.     int origDay;
  3660.     int origMonth;
  3661.     struct tm *time_now;
  3662.     time_t currentTime;
  3663.     short i;
  3664.     short numDaysInMonth;
  3665.  
  3666.     time(¤tTime);
  3667.     time_now = localtime( ¤tTime );
  3668.     numDaysInMonth = numberOfDaysInMonth(month, year);
  3669.  
  3670.     origDay = time_now->tm_mday;
  3671.     origMonth = time_now->tm_mon;
  3672.     time_now->tm_mon = month;
  3673.     time_now->tm_year= year;
  3674.  
  3675.     strftime( temp, sizeof(temp), " %B - %Y ", time_now);
  3676.     WinSetDlgItemText( hWnd, 550, temp );
  3677.  
  3678.     for( i=500; i<543; i++) {
  3679.         WinRemovePresParam( WinWindowFromID(hWnd, i), PP_BACKGROUNDCOLORINDEX );
  3680.         WinRemovePresParam( WinWindowFromID(hWnd, i), PP_FOREGROUNDCOLORINDEX );
  3681.         }
  3682.  
  3683.     for( i=0; i<startDay; i++) {
  3684.         WinSetDlgItemText( hWnd, i+500, "" );
  3685.         WinEnableControl( hWnd, i+500, FALSE );
  3686.         }
  3687.  
  3688.     if (month==origMonth) {
  3689.         WinSetPresParam( WinWindowFromID(hWnd, origDay+startDay+499), PP_BACKGROUNDCOLORINDEX, sizeof(LONG), (PVOID)&backgroundColor );
  3690.         WinSetPresParam( WinWindowFromID(hWnd, origDay+startDay+499), PP_FOREGROUNDCOLORINDEX, sizeof(LONG), (PVOID)&foregroundColor );
  3691.         }
  3692.  
  3693.     for( i=1; i<=numDaysInMonth; i++) {
  3694.         sprintf(temp, "%d", i);
  3695.         WinEnableControl( hWnd, i+startDay+500-1, TRUE );
  3696.         WinSetDlgItemText( hWnd, i+startDay+500-1, temp );
  3697.         }
  3698.  
  3699.     for( i=numDaysInMonth+startDay+500; i<543; i++) {
  3700.         WinSetDlgItemText( hWnd, i, "" );
  3701.         WinEnableControl( hWnd, i, FALSE );
  3702.         }
  3703. }
  3704.  
  3705.  
  3706. ////////////////////////////////////////////////////////////////////////////////
  3707. // return # of days in # (even checking for leap year)
  3708. ////////////////////////////////////////////////////////////////////////////////
  3709. BYTE numberOfDaysInMonth(int month, int year)
  3710. {
  3711.     if (((1900+year) % 4) || (month != 1))
  3712.         return daysInMonth[month];
  3713.     else
  3714.         return daysInMonth[month]+1;    //handle leap year
  3715. }
  3716.  
  3717.  
  3718. ////////////////////////////////////////////////////////////////////////////////
  3719. // display scheduling calendar and let user schedule and revise tasks
  3720. ////////////////////////////////////////////////////////////////////////////////
  3721. MRESULT EXPENTRY schedulerProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  3722. {
  3723.    switch( msg )
  3724.     {
  3725.         //----------------------------------------------------------------------
  3726.         // when the dialog is being initialized, center it on desktop
  3727.         //----------------------------------------------------------------------
  3728.         case WM_INITDLG: {
  3729.             struct tm *time_now;
  3730.             CHAR mesg[24];
  3731.             time_t currentTime;
  3732.             SWP swp;
  3733.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  3734.             WinSetWindowPos( hWnd, (HWND)0,
  3735.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  3736.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  3737.                              0, 0, SWP_MOVE);
  3738.  
  3739.             time(¤tTime);
  3740.             time_now = localtime( ¤tTime );
  3741.             month = time_now->tm_mon;
  3742.             year = time_now->tm_year;
  3743.  
  3744.             startDay = (time_now->tm_wday - (time_now->tm_mday % 7 - 1));
  3745.             if (startDay > 6)
  3746.                 startDay = startDay - 7;
  3747.             else if (startDay < 0)
  3748.                 startDay = startDay + 7;
  3749.             updateCalendar( hWnd );
  3750.  
  3751.             sprintf( mesg, "Every %d Seconds", repeatTime );
  3752.             WinSetDlgItemText( hWnd, REMINDERTIME, mesg );
  3753.  
  3754.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3755.             }
  3756.         //----------------------------------------------------------------------
  3757.         // process a command message from the dialog box
  3758.         //----------------------------------------------------------------------
  3759.         case WM_COMMAND:
  3760.         {
  3761.             USHORT command = SHORT1FROMMP(mp1);
  3762.  
  3763.             //------------------------------------------------------------------
  3764.             // if the user pressed a day button, show daily schedule window
  3765.             //------------------------------------------------------------------
  3766.             if ((command>=500) && (command<=542)) {
  3767.                 day = command - 500 - startDay;
  3768.                 WinDlgBox(HWND_DESKTOP,
  3769.                           hWnd,
  3770.                           (PFNWP)scheduleProc,
  3771.                           0,
  3772.                           SCHEDULEITEM,
  3773.                           (PVOID)NULL);
  3774.                 return 0;
  3775.                 }
  3776.             //------------------------------------------------------------------
  3777.             // handle user commands
  3778.             //------------------------------------------------------------------
  3779.             switch( command ) {
  3780.                 //------------------------------------------------------------------
  3781.                 // show all currently scheduled tasks
  3782.                 //------------------------------------------------------------------
  3783.                 case SHOWALL: {
  3784.                     WinDlgBox(HWND_DESKTOP,
  3785.                               hWnd,
  3786.                               (PFNWP)showAllItemsProc,
  3787.                               0,
  3788.                               SHOWALLITEMS,
  3789.                               (PVOID)NULL);
  3790.                     return 0;
  3791.                     }
  3792.                 //--------------------------------------------------------------
  3793.                 // reduce amount of time between reminder sounds
  3794.                 //--------------------------------------------------------------
  3795.                 case LESSTIME: {
  3796.                     char mesg[24];
  3797.                     if (repeatTime>0)
  3798.                         repeatTime--;
  3799.                     sprintf( mesg, "Every %d Seconds", repeatTime );
  3800.                     WinSetDlgItemText( hWnd, REMINDERTIME, mesg );
  3801.                     return 0;
  3802.                     }
  3803.                 //--------------------------------------------------------------
  3804.                 // increase amount of time between reminder sounds
  3805.                 //--------------------------------------------------------------
  3806.                 case MORETIME: {
  3807.                     char mesg[24];
  3808.                     if (repeatTime<32767)
  3809.                         repeatTime++;
  3810.                     sprintf( mesg, "Every %d Seconds", repeatTime );
  3811.                     WinSetDlgItemText( hWnd, REMINDERTIME, mesg );
  3812.                     return 0;
  3813.                     }
  3814.                 //--------------------------------------------------------------
  3815.                 // go back 1 month
  3816.                 //--------------------------------------------------------------
  3817.                 case 551: {
  3818.                     month--;
  3819.                     if (month < 0) {
  3820.                         month = 11;
  3821.                         year--;
  3822.                         }
  3823.  
  3824.                     startDay = startDay - numberOfDaysInMonth(month, year) % 7;
  3825.  
  3826.                     if (startDay > 6)
  3827.                         startDay = startDay - 7;
  3828.                     if (startDay < 0)
  3829.                         startDay = startDay + 7;
  3830.  
  3831.                     updateCalendar( hWnd );
  3832.                     return 0;
  3833.                     }
  3834.                 //--------------------------------------------------------------
  3835.                 // advance 1 month
  3836.                 //--------------------------------------------------------------
  3837.                 case 553: {
  3838.                     SHORT oldMonth = month;
  3839.                     SHORT oldYear = year;
  3840.  
  3841.                     month++;
  3842.                     if (month > 11) {
  3843.                         month = 0;
  3844.                         year++;
  3845.                         }
  3846.  
  3847.                     startDay = (startDay + numberOfDaysInMonth(oldMonth, oldYear)) % 7;
  3848.                     if (startDay > 6)
  3849.                         startDay = startDay - 7;
  3850.                     if (startDay < 0)
  3851.                         startDay = startDay + 7;
  3852.  
  3853.                     updateCalendar( hWnd );
  3854.                     return 0;
  3855.                     }
  3856.                 //--------------------------------------------------------------
  3857.                 // go back to current month
  3858.                 //--------------------------------------------------------------
  3859.                 case 552: {
  3860.                     time_t currentTime;
  3861.                     struct tm *time_now;
  3862.  
  3863.                     time(¤tTime);
  3864.                     time_now = localtime( ¤tTime );
  3865.                     month = time_now->tm_mon;
  3866.                     year = time_now->tm_year;
  3867.  
  3868.                     startDay = time_now->tm_wday - (time_now->tm_mday % 7 - 1);
  3869.                     if (startDay > 6)
  3870.                         startDay = startDay - 7;
  3871.                     if (startDay < 0)
  3872.                         startDay = startDay + 7;
  3873.  
  3874.                     updateCalendar( hWnd );
  3875.                     return 0;
  3876.                     }
  3877.                 //--------------------------------------------------------------
  3878.                 // user pressed OK, cancel dialog
  3879.                 //--------------------------------------------------------------
  3880.                 case DID_OK: {
  3881.                     WinDismissDlg( hWnd, TRUE );
  3882.                     return 0;
  3883.                 }
  3884.             }
  3885.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3886.         }
  3887.         //----------------------------------------------------------------------
  3888.         // if nothing further we want to intercept, pass message onto system
  3889.         //----------------------------------------------------------------------
  3890.         default:
  3891.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3892.     }
  3893. }
  3894.  
  3895.  
  3896. ////////////////////////////////////////////////////////////////////////////////
  3897. ////////////////////////////////////////////////////////////////////////////////
  3898. MRESULT EXPENTRY showAllItemsProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  3899. {
  3900.    switch( msg )
  3901.     {
  3902.         //----------------------------------------------------------------------
  3903.         // when the dialog is being initialized, center it on desktop
  3904.         //----------------------------------------------------------------------
  3905.         case WM_INITDLG: {
  3906.             USERMENUITEM* userItem;
  3907.             ALARMS* alarm;
  3908.             CHAR temp[64+MAXACTIONSTRINGLENGTH];
  3909.             CHAR s[MAXACTIONSTRINGLENGTH+11];
  3910.             SWP swp;
  3911.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  3912.             WinSetWindowPos( hWnd, (HWND)0,
  3913.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  3914.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  3915.                              0, 0, SWP_MOVE);
  3916.  
  3917.             sprintf(temp, "%d tasks currently scheduled (out of %d possible)", numAlarms, MAXALARMS );
  3918.             WinSetWindowText( hWnd, temp );
  3919.  
  3920.             WinSendDlgItemMsg( hWnd, SHOWITEMS, LM_DELETEALL, MPFROMSHORT( LIT_END ), temp );
  3921.             for( short i = 0; i< numAlarms; i++) {
  3922.                 alarm = alarmPtr[i];
  3923.                 CHAR c = 'a';
  3924.                 //BYTE hour = alarm[i].AlarmHour;
  3925.                 BYTE hour = alarm->AlarmHour;
  3926.  
  3927.                 //if (alarm[i].options & SCHEDULE_LAUNCHAPP) {
  3928.                 if (alarm->options & SCHEDULE_LAUNCHAPP) {
  3929.                     short j = 10;
  3930.                     short k = 0;
  3931.                     strcpy(s, "Launch >> ");
  3932. //                    while ((ItemName[((int)alarm[i].ActionToDo[0])][((int)alarm[i].ActionToDo[1])][k])!='\0')
  3933. //                        if ((ItemName[((int)alarm[i].ActionToDo[0])][((int)alarm[i].ActionToDo[1])][k])=='~')
  3934.                     userItem = Menus[((int)alarm->ActionToDo[0])][((int)alarm->ActionToDo[1])];
  3935.                     while (userItem->ItemName[k] != '\0')
  3936.                         if (userItem->ItemName[k] == '~')
  3937.                             k++;
  3938.                         else
  3939. //                            s[j++] = ItemName[((int)alarm[i].ActionToDo[0])][((int)alarm[i].ActionToDo[1])][k++];
  3940.                             s[j++] = userItem->ItemName[k++];
  3941.                         s[j] = '\0';
  3942.                     }
  3943.                 else
  3944.                     //strcpy(s, alarm[i].ActionToDo);
  3945.                     strcpy(s, alarm->ActionToDo);
  3946.  
  3947.                 //if (alarm[i].AlarmHour>11)
  3948.                 if (alarm->AlarmHour>11)
  3949.                     c='p';
  3950.                 if (!(hour = hour % 12))
  3951.                     hour = 12;
  3952.  
  3953.                 sprintf( temp, "%2d:%2d%cm (%2d:%2d) -- %d/%d/%d (%d/%d/%d) -- %s", hour,
  3954.                                                                     alarm->AlarmMinute,
  3955.                                                                     c,
  3956.                                                                     alarm->AlarmHour,
  3957.                                                                     alarm->AlarmMinute,
  3958.                                                                     alarm->AlarmMonth+1,
  3959.                                                                     alarm->AlarmDay+1,
  3960.                                                                     alarm->AlarmYear,
  3961.                                                                     alarm->AlarmDay+1,
  3962.                                                                     alarm->AlarmMonth+1,
  3963.                                                                     alarm->AlarmYear,
  3964.                                                                     s );
  3965. /*
  3966.                 sprintf( temp, "%2d:%2d%cm (%2d:%2d) -- %d/%d/%d (%d/%d/%d) -- %s", hour,
  3967.                                                                     alarm[i].AlarmMinute,
  3968.                                                                     c,
  3969.                                                                     alarm[i].AlarmHour,
  3970.                                                                     alarm[i].AlarmMinute,
  3971.                                                                     alarm[i].AlarmMonth+1,
  3972.                                                                     alarm[i].AlarmDay+1,
  3973.                                                                     alarm[i].AlarmYear,
  3974.                                                                     alarm[i].AlarmDay+1,
  3975.                                                                     alarm[i].AlarmMonth+1,
  3976.                                                                     alarm[i].AlarmYear,
  3977.                                                                     s );
  3978. */
  3979.                 if (temp[3]==' ') {
  3980.                     temp[3] = '0';
  3981.                     temp[12]= '0';
  3982.                     }
  3983.  
  3984.                 WinSendDlgItemMsg( hWnd, SHOWITEMS, LM_INSERTITEM, MPFROMSHORT( LIT_END ), temp );
  3985.                 }
  3986.  
  3987.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3988.             }
  3989.         //----------------------------------------------------------------------
  3990.         //----------------------------------------------------------------------
  3991.         case WM_CONTROL:
  3992.         {
  3993.             if (SHORT2FROMMP(mp1)==LN_ENTER) {
  3994.                 SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, SHOWITEMS,
  3995.                                                                       LM_QUERYSELECTION,
  3996.                                                                       MPFROM2SHORT( LIT_FIRST, 0 ),
  3997.                                                                       0 ) );
  3998.  
  3999.                 oldProgType = numAlarms;
  4000.                 numAlarms = 0;
  4001.  
  4002.                 reviseScheduledItem( itemSelected );
  4003.                 sortTimeEntries( oldProgType );
  4004.                 numAlarms = oldProgType;
  4005.                 WinSendMsg( hWnd, WM_INITDLG, 0, 0 );
  4006.                 WinSendDlgItemMsg( hWnd, SHOWITEMS, LM_SELECTITEM,
  4007.                                    MPFROM2SHORT( itemSelected, 0 ),
  4008.                                    MPFROM2SHORT( TRUE, 0 ) );
  4009.                 return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4010.                 }
  4011.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4012.         }
  4013.         //----------------------------------------------------------------------
  4014.         // if we receive any system message, dismiss the dialog box
  4015.         //----------------------------------------------------------------------
  4016.         case WM_COMMAND:
  4017.         {
  4018.             if (SHORT1FROMMP(mp1)==DID_OK)
  4019.                 WinDismissDlg( hWnd, TRUE );
  4020.             return 0;
  4021.         }
  4022.         //----------------------------------------------------------------------
  4023.         // if nothing further we want to intercept, pass message onto system
  4024.         //----------------------------------------------------------------------
  4025.         default:
  4026.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4027.     }
  4028. }
  4029.  
  4030.  
  4031. ////////////////////////////////////////////////////////////////////////////////
  4032. ////////////////////////////////////////////////////////////////////////////////
  4033. MRESULT EXPENTRY scheduleProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  4034. {
  4035.     switch( msg )
  4036.     {
  4037.         //----------------------------------------------------------------------
  4038.         // when the dialog is being initialized, center it on desktop
  4039.         //----------------------------------------------------------------------
  4040.         case WM_INITDLG: {
  4041.             CHAR temp[MAXACTIONSTRINGLENGTH+32];
  4042.             SWP swp;
  4043.             SHORT i;
  4044.             ALARMS* alarm;
  4045.             USERMENUITEM* menuItem;
  4046.  
  4047.             // disable alarms while editing calendar
  4048.             oldProgType = numAlarms;
  4049.             numAlarms = 0;
  4050.  
  4051.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  4052.             WinSetWindowPos( hWnd, (HWND)0,
  4053.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  4054.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  4055.                              0, 0, SWP_MOVE);
  4056.  
  4057.             sprintf( temp, "Schedule for %d/%d/%4d...", month+1, day+1, 1900+year);
  4058.             WinSetWindowText( hWnd, temp );
  4059.  
  4060.             WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS, LM_DELETEALL, MPFROMSHORT( LIT_END ), temp );
  4061.  
  4062.             for( i = 0; i< oldProgType; i++) {
  4063.                 alarm = alarmPtr[i];
  4064.                 if (alarm->AlarmDay == day)
  4065.                   if (alarm->AlarmMonth == month)
  4066.                     if (alarm->AlarmYear == year) {
  4067.                         CHAR c = 'a';
  4068.                         CHAR s[11+MAXACTIONSTRINGLENGTH];
  4069.                         BYTE hour = alarm->AlarmHour;
  4070.  
  4071.                         if (alarm->options & SCHEDULE_LAUNCHAPP) {
  4072.                             short j = 10;
  4073.                             short k = 0;
  4074.                             strcpy(s, "Launch >> ");
  4075.                             menuItem = Menus[((int)alarmPtr[i]->ActionToDo[0])][((int)alarmPtr[i]->ActionToDo[1])];
  4076.                             while (menuItem->ItemName[k] !='\0')
  4077.                                 if (menuItem->ItemName[k] =='~')
  4078.                                     k++;
  4079.                                 else
  4080.                                     s[j++] = menuItem->ItemName[k++];
  4081.                             s[j] = '\0';
  4082.                             }
  4083.                         else
  4084.                             strcpy(s, alarm->ActionToDo);
  4085.  
  4086.                         if (alarm->AlarmHour>11)
  4087.                             c='p';
  4088.                         if (!(hour = hour % 12))
  4089.                             hour = 12;
  4090.  
  4091.                         sprintf( temp, "%2d:%2d%cm (%2d:%2d) -- %s", hour,
  4092.                                                                     alarm->AlarmMinute,
  4093.                                                                     c,
  4094.                                                                     alarm->AlarmHour,
  4095.                                                                     alarm->AlarmMinute,
  4096.                                                                     s );
  4097.                         if (temp[3]==' ') {
  4098.                             temp[3] = '0';
  4099.                             temp[12]= '0';
  4100.                             }
  4101.  
  4102.  
  4103.                         WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS, LM_INSERTITEM, MPFROMSHORT( LIT_END ), temp );
  4104.                         }
  4105.                 }
  4106.  
  4107.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4108.             }
  4109.         //----------------------------------------------------------------------
  4110.         //----------------------------------------------------------------------
  4111.         case WM_CONTROL:
  4112.         {
  4113.             if ((SHORT1FROMMP(mp1)==SCHEDULEDITEMS) && (SHORT2FROMMP(mp1)==LN_ENTER))
  4114.                 return WinSendMsg( hWnd, WM_COMMAND, MPFROM2SHORT( REVISEITEM, 0 ), mp2 );
  4115.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4116.         }
  4117.         //----------------------------------------------------------------------
  4118.         //----------------------------------------------------------------------
  4119.         case WM_COMMAND:
  4120.         {
  4121.             USHORT command = SHORT1FROMMP(mp1);
  4122.  
  4123.             //------------------------------------------------------------------
  4124.             //------------------------------------------------------------------
  4125.             if ( command==DELETEITEM ) {
  4126.                 BOOL continueOn = TRUE;
  4127.                 SHORT index = 0;
  4128.                 SHORT item = 0;
  4129.                 SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS,
  4130.                                                                       LM_QUERYSELECTION,
  4131.                                                                       MPFROM2SHORT( LIT_FIRST, 0 ),
  4132.                                                                       0 ) );
  4133.                 if (itemSelected==LIT_NONE) {
  4134.                     WinMessageBox( HWND_DESKTOP, hwndFrame,
  4135.                                    "You must select an item!",
  4136.                                    "Delete an item", 0,
  4137.                                    MB_MOVEABLE|MB_ERROR|MB_OK);
  4138.                     return 0;
  4139.                     }
  4140.  
  4141.                 if (WinMessageBox( HWND_DESKTOP, hwndFrame,
  4142.                                    "Are you sure you want to permanently delete this item?",
  4143.                                    "Delete an item", 0,
  4144.                                    MB_MOVEABLE|MB_ICONQUESTION|MB_YESNO) == MBID_NO)
  4145.                     return 0;
  4146.  
  4147.                 itemSelected++;
  4148.                 while (continueOn) {
  4149.                     if ((alarmPtr[index]->AlarmYear  == (BYTE)(year%100)) &&
  4150.                         (alarmPtr[index]->AlarmMonth == (BYTE)(month%14)) &&
  4151.                         (alarmPtr[index]->AlarmDay   == (BYTE)(day%40))) {
  4152.                             item++;
  4153.                             if (item == itemSelected)
  4154.                                 continueOn = FALSE;
  4155.                             }
  4156.                     index++;
  4157.                     }
  4158.  
  4159.                 delete alarmPtr[index-1];
  4160.                 {
  4161.                     struct ALARMS* tmp;
  4162.                     //struct ALARMS tmp;
  4163.                     for ( item=index-1; item<MAXALARMS-1; item++) {
  4164.                         tmp = alarmPtr[item];
  4165.                         alarmPtr[item]   = alarmPtr[item+1];
  4166.                         alarmPtr[item+1] = tmp;
  4167.                         }
  4168.                 }
  4169.                 numAlarms = oldProgType-1;
  4170.                 sortTimeEntries( numAlarms );
  4171.                 WinSendMsg( hWnd, WM_INITDLG, 0, 0 );
  4172.                 if (index-1 >= oldProgType)
  4173.                     WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS, LM_SELECTITEM,
  4174.                                        MPFROM2SHORT( oldProgType-1, 0 ),
  4175.                                        MPFROM2SHORT( TRUE, 0 ) );
  4176.                 else
  4177.                     WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS, LM_SELECTITEM,
  4178.                                        MPFROM2SHORT( index-1, 0 ),
  4179.                                        MPFROM2SHORT( TRUE, 0 ) );
  4180.                 return 0;
  4181.                 }
  4182.             //------------------------------------------------------------------
  4183.             //------------------------------------------------------------------
  4184.             if ( command==ADDITEM ) {
  4185.                 ALARMS* alarm;
  4186.                 SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS,
  4187.                                                                       LM_QUERYSELECTION,
  4188.                                                                       MPFROM2SHORT( LIT_FIRST, 0 ),
  4189.                                                                       0 ) );
  4190.                 if (oldProgType == MAXALARMS) {
  4191.                     WinMessageBox( HWND_DESKTOP, hwndFrame,
  4192.                                    "There is no room for an additional task entry!",
  4193.                                    "Task Scheduler", 0,
  4194.                                    MB_MOVEABLE|MB_ERROR|MB_OK);
  4195.                     return 0;
  4196.                     }
  4197.  
  4198.                 alarmPtr[oldProgType] = new ALARMS;
  4199.                 alarm = alarmPtr[oldProgType];
  4200.                 alarm->AlarmYear = (BYTE)(year%100);
  4201.                 alarm->AlarmMonth = (BYTE)(month%14);
  4202.                 alarm->AlarmDay = (BYTE)(day%40);
  4203.                 alarm->AlarmHour = 0;
  4204.                 alarm->AlarmMinute = 0;
  4205.                 alarm->options = SCHEDULE_USEWAVFILE | SCHEDULE_USEWAVFILE;
  4206.                 alarm->ActionToDo[0] = 0;
  4207.                 alarm->ReminderWAV[0] = 0;
  4208.                 oldProgType++;
  4209.                 reviseScheduledItem( oldProgType-1 );
  4210.                 sortTimeEntries( oldProgType );
  4211.                 numAlarms = oldProgType;
  4212.                 WinSendMsg( hWnd, WM_INITDLG, 0, 0 );
  4213.                 WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS, LM_SELECTITEM,
  4214.                                    MPFROM2SHORT( itemSelected, 0 ),
  4215.                                    MPFROM2SHORT( TRUE, 0 ) );
  4216.                 return 0;
  4217.                 }
  4218.             //------------------------------------------------------------------
  4219.             //------------------------------------------------------------------
  4220.             if (( command==REVISEITEM ) || (command==LN_ENTER)) {
  4221.                 BOOL continueOn = TRUE;
  4222.                 SHORT index = 0;
  4223.                 SHORT item = 0;
  4224.                 SHORT itemSelected = 1 + SHORT1FROMMP( WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS,
  4225.                                                                           LM_QUERYSELECTION,
  4226.                                                                           MPFROM2SHORT( LIT_FIRST, 0 ),
  4227.                                                                           0 ) );
  4228.  
  4229.                 if ( (itemSelected-1) == LIT_NONE ) {
  4230.                     WinMessageBox( HWND_DESKTOP, hwndFrame,
  4231.                                    "You must select an item!",
  4232.                                    "Revise an item", 0,
  4233.                                    MB_MOVEABLE|MB_ERROR|MB_OK);
  4234.                     return 0;
  4235.                     }
  4236.  
  4237.                 while (continueOn) {
  4238.                     if ((alarmPtr[index]->AlarmYear  == (BYTE)(year%100)) &&
  4239.                         (alarmPtr[index]->AlarmMonth == (BYTE)(month%14)) &&
  4240.                         (alarmPtr[index]->AlarmDay   == (BYTE)(day%40))) {
  4241.                             item++;
  4242.                             if (item == itemSelected)
  4243.                                 continueOn = FALSE;
  4244.                             }
  4245.                     index++;
  4246.                     }
  4247.                 reviseScheduledItem( index-1 );
  4248.                 sortTimeEntries( oldProgType );
  4249.                 numAlarms = oldProgType;
  4250.                 WinSendMsg( hWnd, WM_INITDLG, 0, 0 );
  4251.                 WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS, LM_SELECTITEM,
  4252.                                    MPFROM2SHORT( itemSelected-1, 0 ),
  4253.                                    MPFROM2SHORT( TRUE, 0 ) );
  4254.                 return 0;
  4255.                 }
  4256.             //------------------------------------------------------------------
  4257.             //------------------------------------------------------------------
  4258.             if ( command==DID_OK ) {
  4259.                 WinDismissDlg( hWnd, TRUE );
  4260.                 numAlarms = oldProgType;
  4261.                 return 0;
  4262.                 }
  4263.             }
  4264.         default:
  4265.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4266.     }
  4267. }
  4268.  
  4269.  
  4270. ////////////////////////////////////////////////////////////////////////////////
  4271. ////////////////////////////////////////////////////////////////////////////////
  4272. VOID checkAlarms( SHORT hour, SHORT minute, SHORT month, SHORT day, SHORT year ) {
  4273.     ALARMS* alarm = alarmPtr[0];
  4274.     struct tm *time_now;
  4275.     time_t currentTime;
  4276.  
  4277.     day--;
  4278.     if ((numAlarms == 0) || (alarm->AlarmYear > year ))
  4279.         return;
  4280.     if ((alarm->AlarmYear == year) && (alarm->AlarmMonth > month))
  4281.         return;
  4282.     if ((alarm->AlarmMonth == month) && (alarm->AlarmDay > day))
  4283.         return;
  4284.     if ((alarm->AlarmDay == day) && (alarm->AlarmHour > hour))
  4285.         return;
  4286.     if ((alarm->AlarmHour == hour) && (alarm->AlarmMinute > minute))
  4287.         return;
  4288.  
  4289.     if ((alarm->options & SCHEDULE_LAUNCHAPP) && (!(alarm->options & SCHEDULE_SOUNDONLY)))
  4290.         startApplication( (SHORT)alarm->ActionToDo[0], (SHORT)alarm->ActionToDo[1] );
  4291.     else {
  4292.         currentReminderWavFile = 0;
  4293.         if (alarm->options & SCHEDULE_USEWAVFILE)
  4294.             currentReminderWavFile = alarm->ReminderWAV;
  4295.         if (alarm->options & SCHEDULE_SOUNDONLY)
  4296.             ringChime( currentReminderWavFile );
  4297.         else {
  4298.             oldItemName[0] = TRUE;
  4299.             WinDlgBox(HWND_DESKTOP,
  4300.             hwndFrame,
  4301.             (PFNWP)reminderNoteProc,
  4302.             0,
  4303.             REMINDER_DIALOG,
  4304.             (PVOID)alarm->ActionToDo);
  4305.             if (oldItemName[0]) {
  4306.                 checkAlarms( hour, minute, month, day, year );
  4307.                 return;
  4308.                 }
  4309.             }
  4310.         }
  4311.  
  4312.         // make it so that we reschedule from the current time
  4313.         // and not the time the task was supposed to go off
  4314.         tzset();
  4315.         time(¤tTime);
  4316.         time_now = localtime( ¤tTime );
  4317.  
  4318.         // reschedule or delete note
  4319.         if (alarm->options & SCHEDULE_EVERYHOUR) {
  4320.             alarm->AlarmHour = time_now->tm_hour;
  4321.             alarm->AlarmDay = time_now->tm_mday-1;
  4322.             alarm->AlarmMonth = time_now->tm_mon;
  4323.             alarm->AlarmYear = time_now->tm_year;
  4324.  
  4325.             alarm->AlarmHour++;
  4326.             validateTimeEntry();
  4327.             sortTimeEntries( numAlarms );
  4328.             }
  4329.         else if (alarm->options & SCHEDULE_EVERYDAY) {
  4330.             alarm->AlarmDay = time_now->tm_mday-1;
  4331.             alarm->AlarmMonth = time_now->tm_mon;
  4332.             alarm->AlarmYear = time_now->tm_year;
  4333.             alarm->AlarmDay++;
  4334.             validateTimeEntry();
  4335.             sortTimeEntries( numAlarms );
  4336.             }
  4337.         else if (alarmPtr[0]->options & SCHEDULE_EVERYWEEK) {
  4338.             alarm->AlarmDay = time_now->tm_mday-1;
  4339.             alarm->AlarmMonth = time_now->tm_mon;
  4340.             alarm->AlarmYear = time_now->tm_year;
  4341.             alarm->AlarmDay = alarm->AlarmDay + 7;
  4342.             validateTimeEntry();
  4343.             sortTimeEntries( numAlarms );
  4344.             }
  4345.         else if (alarm->options & SCHEDULE_EVERYMONTH) {
  4346.             alarm->AlarmMonth = time_now->tm_mon;
  4347.             alarm->AlarmYear = time_now->tm_year;
  4348.             alarm->AlarmMonth++;
  4349.             validateTimeEntry();
  4350.             sortTimeEntries( numAlarms );
  4351.             }
  4352.         else if (alarm->options & SCHEDULE_EVERYYEAR) {
  4353.             alarm->AlarmYear = time_now->tm_year;
  4354.             alarm->AlarmYear++;
  4355.             validateTimeEntry();
  4356.             sortTimeEntries( numAlarms );
  4357.             }
  4358.         else {
  4359.         ////// delete the reminder we just performed ///////
  4360.             delete alarm;
  4361.             for (short i=0; i<numAlarms-1; i++)
  4362.                 alarmPtr[i] = alarmPtr[i+1];
  4363.             numAlarms--;
  4364.             }
  4365.         // check to see if another alarm needs to be serviced
  4366.         checkAlarms( hour, minute, month, day, year );
  4367. }
  4368.  
  4369.  
  4370. ////////////////////////////////////////////////////////////////////////////////
  4371. ////////////////////////////////////////////////////////////////////////////////
  4372. VOID validateTimeEntry( VOID )
  4373. {
  4374.     ALARMS* alarm = alarmPtr[0];
  4375.  
  4376.     if (alarm->AlarmMinute > 59) {
  4377.         alarm->AlarmMinute = alarm->AlarmMinute - 60;
  4378.         alarm->AlarmHour++;
  4379.         }
  4380.     if (alarm->AlarmHour > 23) {
  4381.         alarm->AlarmMinute = alarm->AlarmMinute - 24;
  4382.         alarm->AlarmDay++;
  4383.         }
  4384.     if (alarm->AlarmDay > daysInMonth[alarm->AlarmMonth] ) {
  4385.         alarm->AlarmDay = alarm->AlarmDay - daysInMonth[alarm->AlarmMonth];
  4386.         alarm->AlarmMonth++;
  4387.         }
  4388.     if (alarm->AlarmMonth > 11) {
  4389.         alarm->AlarmMonth = alarm->AlarmMonth - 12;
  4390.         alarm->AlarmYear++;
  4391.         }
  4392. }
  4393.  
  4394.  
  4395. ////////////////////////////////////////////////////////////////////////////////
  4396. ////////////////////////////////////////////////////////////////////////////////
  4397. VOID swapTwoTimeEntries( INT entry1, INT entry2 )
  4398. {
  4399.     ALARMS* tmp;
  4400.  
  4401.     tmp = alarmPtr[entry1];
  4402.     alarmPtr[entry1] = alarmPtr[entry2];
  4403.     alarmPtr[entry2] = tmp;
  4404. }
  4405.  
  4406.  
  4407. ////////////////////////////////////////////////////////////////////////////////
  4408. ////////////////////////////////////////////////////////////////////////////////
  4409. VOID sortTimeEntries( INT entries )
  4410. {
  4411.     short i,j;
  4412.  
  4413.     // bubble sort all scheduled events so that closest event tops the list
  4414.     for (i=0; i<entries; i++)
  4415.         for (j=0; j<entries-1; j++)
  4416.             if ( alarmPtr[j]->AlarmMinute > alarmPtr[j+1]->AlarmMinute )
  4417.                 swapTwoTimeEntries(j, j+1);
  4418.     for (i=0; i<entries; i++)
  4419.         for (j=0; j<entries-1; j++)
  4420.             if ( alarmPtr[j]->AlarmHour > alarmPtr[j+1]->AlarmHour )
  4421.                 swapTwoTimeEntries(j, j+1);
  4422.     for (i=0; i<entries; i++)
  4423.         for (j=0; j<entries-1; j++)
  4424.             if ( alarmPtr[j]->AlarmDay > alarmPtr[j+1]->AlarmDay )
  4425.                 swapTwoTimeEntries(j, j+1);
  4426.     for (i=0; i<entries; i++)
  4427.         for (j=0; j<entries-1; j++)
  4428.             if ( alarmPtr[j]->AlarmMonth > alarmPtr[j+1]->AlarmMonth )
  4429.                 swapTwoTimeEntries(j, j+1);
  4430.     for (i=0; i<entries; i++)
  4431.         for (j=0; j<entries-1; j++)
  4432.             if ( alarmPtr[j]->AlarmYear > alarmPtr[j+1]->AlarmYear )
  4433.                 swapTwoTimeEntries(j, j+1);
  4434. }
  4435.  
  4436.  
  4437. ////////////////////////////////////////////////////////////////////////////////
  4438. // reviseScheduledItem - call dialog box to revise a currently scheduled event
  4439. ////////////////////////////////////////////////////////////////////////////////
  4440. VOID reviseScheduledItem( INT itemToEdit )
  4441. {
  4442.     EditItem = itemToEdit;
  4443.     WinDlgBox(HWND_DESKTOP,
  4444.               hwndFrame,
  4445.               (PFNWP)itemProc,
  4446.               0,
  4447.               SCHEDULEITEMDIALOG,
  4448.               (PVOID)0);
  4449.     return;
  4450. }
  4451.  
  4452.  
  4453. ////////////////////////////////////////////////////////////////////////////////
  4454. // displayReminderTime - update display of time in revision dialog box
  4455. ////////////////////////////////////////////////////////////////////////////////
  4456. VOID displayReminderTime( HWND hWnd, INT offset )
  4457. {
  4458.     SHORT hour;
  4459.     CHAR c;
  4460.     CHAR time[16];
  4461.     ALARMS* alarm = alarmPtr[offset];
  4462.  
  4463.     c='a';
  4464.     if (alarm->AlarmHour>11)
  4465.         c='p';
  4466.     if (!(hour = alarm->AlarmHour % 12))
  4467.         hour = 12;
  4468.  
  4469.     sprintf( time, "%2d:%2d%cm (%2d:%2d)", hour,
  4470.                                            alarm->AlarmMinute,
  4471.                                            c,
  4472.                                            alarm->AlarmHour,
  4473.                                            alarm->AlarmMinute);
  4474.     if (time[3]==' ') {
  4475.         time[3] = '0';
  4476.         time[12]= '0';
  4477.         }
  4478.     WinSetDlgItemText( hWnd, TIME_TEXT, (CHAR*)time );
  4479. }
  4480.  
  4481.  
  4482. ////////////////////////////////////////////////////////////////////////////////
  4483. // displayReminderDate - update display of date in revision dialog box
  4484. ////////////////////////////////////////////////////////////////////////////////
  4485. VOID displayReminderDate( HWND hWnd, INT offset )
  4486. {
  4487.     ALARMS* alarm = alarmPtr[offset];
  4488.     CHAR date[24];
  4489.  
  4490.     sprintf( date, " %d/%d/%d (%d/%d/%d) ",  alarm->AlarmMonth+1,
  4491.                                              alarm->AlarmDay+1,
  4492.                                              alarm->AlarmYear,
  4493.                                              alarm->AlarmDay+1,
  4494.                                              alarm->AlarmMonth+1,
  4495.                                              alarm->AlarmYear);
  4496.     WinSetDlgItemText( hWnd, DATETEXT, (CHAR*)date );
  4497. }
  4498.  
  4499.  
  4500. ////////////////////////////////////////////////////////////////////////////////
  4501. ////////////////////////////////////////////////////////////////////////////////
  4502. MRESULT EXPENTRY itemProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  4503. {
  4504.    ALARMS* alarm = alarmPtr[EditItem];
  4505.  
  4506.    switch( msg )
  4507.     {
  4508.         //----------------------------------------------------------------------
  4509.         //----------------------------------------------------------------------
  4510.         case WM_INITDLG: {
  4511.             CHAR s[MAXPATH+11];
  4512.             SWP swp;
  4513.             //ALARMS* alarm = alarmPtr[EditItem];
  4514.  
  4515.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  4516.             WinSetWindowPos( hWnd, (HWND)0,
  4517.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  4518.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  4519.                              0, 0, SWP_MOVE);
  4520.  
  4521.             WinSendDlgItemMsg( hWnd, SOUNDFILE, EM_SETTEXTLIMIT, MPFROMSHORT( MAXACTIONSTRINGLENGTH ), 0 );
  4522.             WinSendDlgItemMsg( hWnd, REMINDER, EM_SETTEXTLIMIT, MPFROMSHORT( MAXACTIONSTRINGLENGTH ), 0 );
  4523.  
  4524.             WinCheckButton( hWnd, DELETEITEM, TRUE );
  4525.             if (alarm->options & SCHEDULE_EVERYHOUR)
  4526.                 WinCheckButton( hWnd, EVERYHOUR, TRUE );
  4527.             else if (alarm->options & SCHEDULE_EVERYDAY)
  4528.                 WinCheckButton( hWnd, EVERYDAY, TRUE );
  4529.             else if (alarm->options & SCHEDULE_EVERYWEEK)
  4530.                 WinCheckButton( hWnd, EVERYWEEK, TRUE );
  4531.             else if (alarm->options & SCHEDULE_EVERYMONTH)
  4532.                 WinCheckButton( hWnd, EVERYMONTH, TRUE );
  4533.             else if (alarm->options & SCHEDULE_EVERYYEAR)
  4534.                 WinCheckButton( hWnd, EVERYYEAR, TRUE );
  4535.  
  4536.             if ( alarm->options & SCHEDULE_USEWAVFILE )
  4537.                 WinCheckButton( hWnd, PLAYSOUND, TRUE );
  4538.             if ( alarm->options & SCHEDULE_SOUNDONLY )
  4539.                 WinCheckButton( hWnd, SOUNDONLY, TRUE );
  4540.  
  4541.             WinSetDlgItemText( hWnd, SOUNDFILE, (CHAR*)alarm->ReminderWAV );
  4542.             displayReminderTime( hWnd, EditItem );
  4543.             displayReminderDate( hWnd, EditItem );
  4544.  
  4545.             if (alarm->options & SCHEDULE_LAUNCHAPP) {
  4546.                 short j = 10;
  4547.                 short k = 0;
  4548.                 USERMENUITEM* menuItem = Menus[((int)alarmPtr[EditItem]->ActionToDo[0])][((int)alarmPtr[EditItem]->ActionToDo[1])];
  4549.  
  4550.                 strcpy(s, "Launch >> ");
  4551.                 while (menuItem->ItemName[k] !='\0')
  4552.                     if (menuItem->ItemName[k] =='~')
  4553.                         k++;
  4554.                     else
  4555.                         s[j++] = menuItem->ItemName[k++];
  4556.                 s[j] = '\0';
  4557.  
  4558.                 WinSetDlgItemText( hWnd, REMINDER, (CHAR*)s );
  4559.                 WinEnableControl( hWnd, REMINDER, FALSE );
  4560.                 }
  4561.             else {
  4562.                 WinEnableControl( hWnd, REMINDER, TRUE );
  4563.                 WinSetDlgItemText( hWnd, REMINDER, (CHAR*)alarm->ActionToDo );
  4564.                 }
  4565.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4566.             }
  4567.         //----------------------------------------------------------------------
  4568.         //----------------------------------------------------------------------
  4569.         case WM_COMMAND:
  4570.         {
  4571.             USHORT command = SHORT1FROMMP(mp1);
  4572.  
  4573.  
  4574.             switch(command) {
  4575.             //------------------------------------------------------------------
  4576.             //------------------------------------------------------------------
  4577.                 case LAUNCHITEM: {
  4578.                     short tmp = 0;
  4579.  
  4580.                     if (WinQueryButtonCheckstate( hWnd, EVERYHOUR ))
  4581.                         tmp += SCHEDULE_EVERYHOUR;
  4582.                     else if (WinQueryButtonCheckstate( hWnd, EVERYDAY ))
  4583.                         tmp += SCHEDULE_EVERYDAY;
  4584.                     else if (WinQueryButtonCheckstate( hWnd, EVERYWEEK ))
  4585.                         tmp += SCHEDULE_EVERYWEEK;
  4586.                     else if (WinQueryButtonCheckstate( hWnd, EVERYMONTH ))
  4587.                         tmp += SCHEDULE_EVERYMONTH;
  4588.                     else if (WinQueryButtonCheckstate( hWnd, EVERYYEAR ))
  4589.                         tmp += SCHEDULE_EVERYYEAR;
  4590.                     if (WinQueryButtonCheckstate( hWnd, PLAYSOUND ))
  4591.                         tmp += SCHEDULE_USEWAVFILE;
  4592.                     if (WinQueryButtonCheckstate( hWnd, SOUNDONLY ))
  4593.                         tmp += SCHEDULE_SOUNDONLY;
  4594.  
  4595.                     WinDlgBox(HWND_DESKTOP,
  4596.                               hWnd,
  4597.                               (PFNWP)LaunchItemProc,
  4598.                               0,
  4599.                               LAUNCHITEMDIALOG,
  4600.                               (PVOID)0);
  4601.  
  4602.                     if (alarm->options & SCHEDULE_LAUNCHAPP)
  4603.                         tmp = tmp + SCHEDULE_LAUNCHAPP;
  4604.  
  4605.                     alarm->options = tmp;
  4606.                     WinSendMsg( hWnd, WM_INITDLG, 0, 0 );
  4607.                     return 0;
  4608.                     }
  4609.             //------------------------------------------------------------------
  4610.             //------------------------------------------------------------------
  4611.                 case SELECTSOUNDFILE: {
  4612.                     CHAR title[] = "Task Scheduler - Find a Sound File";
  4613.                     HWND hwndDialog;
  4614.                     CHAR oldDir[MAXPATH];
  4615.  
  4616.                     fileDlgInfo.fl = FDS_OPEN_DIALOG|FDS_CENTER;
  4617.                     fileDlgInfo.pszTitle = title;
  4618.                     strcpy( oldDir, fileDlgInfo.szFullFile );
  4619.                     strcat(fileDlgInfo.szFullFile, "*.WAV\0");
  4620.  
  4621.                     hwndDialog = WinFileDlg( HWND_DESKTOP, hWnd, &fileDlgInfo );
  4622.                     if (hwndDialog && (fileDlgInfo.lReturn == DID_OK)) {
  4623.                         strcpy( alarm->ReminderWAV, fileDlgInfo.szFullFile );
  4624.                         strcat( alarm->ReminderWAV, "\0" );
  4625.                         resetFileDialog();
  4626.  
  4627.                         /*
  4628.                         s=0;
  4629.                         while(fileDlgInfo.szFullFile[s]!='\0')
  4630.                             s++;
  4631.                         while((fileDlgInfo.szFullFile[s]!='\\') && (s>=0))
  4632.                             s--;
  4633.  
  4634.                         if (fileDlgInfo.szFullFile[s]=='\\')
  4635.                             fileDlgInfo.szFullFile[s+1]='\0';
  4636.                         else
  4637.                             fileDlgInfo.szFullFile[0]='\0';
  4638.                         */
  4639.  
  4640.                         WinSetDlgItemText( hWnd, SOUNDFILE, alarm->ReminderWAV );
  4641.                         }
  4642.                     else
  4643.                         strcpy( fileDlgInfo.szFullFile, oldDir );
  4644.                     return 0;
  4645.                     }
  4646.             //------------------------------------------------------------------
  4647.             //------------------------------------------------------------------
  4648.                 case DAY_MORE: {
  4649.                     alarm->AlarmDay = (alarm->AlarmDay + 1) % daysInMonth[alarm->AlarmMonth];
  4650.                     displayReminderDate( hWnd, EditItem );
  4651.                     return 0;
  4652.                     }
  4653.             //------------------------------------------------------------------
  4654.             //------------------------------------------------------------------
  4655.                 case DAY_LESS: {
  4656.                     if (alarm->AlarmDay==0)
  4657.                         alarm->AlarmDay = daysInMonth[alarm->AlarmMonth] - 1;
  4658.                     else
  4659.                         alarm->AlarmDay = (alarm->AlarmDay - 1) % daysInMonth[alarm->AlarmMonth];
  4660.                     displayReminderDate( hWnd, EditItem );
  4661.                     return 0;
  4662.                     }
  4663.             //------------------------------------------------------------------
  4664.             //------------------------------------------------------------------
  4665.                 case MONTH_MORE: {
  4666.                     alarm->AlarmMonth = (alarm->AlarmMonth + 1) % 12;
  4667.                     displayReminderDate( hWnd, EditItem );
  4668.                     return 0;
  4669.                     }
  4670.             //------------------------------------------------------------------
  4671.             //------------------------------------------------------------------
  4672.                 case MONTH_LESS: {
  4673.                     if (alarm->AlarmMonth == 0)
  4674.                         alarm->AlarmMonth = 11;
  4675.                     else
  4676.                         alarm->AlarmMonth--;
  4677.                     displayReminderDate( hWnd, EditItem );
  4678.                     return 0;
  4679.                     }
  4680.             //------------------------------------------------------------------
  4681.             //------------------------------------------------------------------
  4682.                 case YEAR_MORE: {
  4683.                     alarm->AlarmYear++;
  4684.                     displayReminderDate( hWnd, EditItem );
  4685.                     return 0;
  4686.                     }
  4687.             //------------------------------------------------------------------
  4688.             //------------------------------------------------------------------
  4689.                 case YEAR_LESS: {
  4690.                     alarm->AlarmYear--;
  4691.                     displayReminderDate( hWnd, EditItem );
  4692.                     return 0;
  4693.                     }
  4694.             //------------------------------------------------------------------
  4695.             //------------------------------------------------------------------
  4696.                 case MINUTE_MORE: {
  4697.                     alarm->AlarmMinute = (alarm->AlarmMinute+1) % 60;
  4698.                     displayReminderTime( hWnd, EditItem );
  4699.                     return 0;
  4700.                     }
  4701.             //------------------------------------------------------------------
  4702.             //------------------------------------------------------------------
  4703.                 case MINUTE_LESS: {
  4704.                     if (alarm->AlarmMinute == 0)
  4705.                         alarm->AlarmMinute = 59;
  4706.                     else
  4707.                         alarm->AlarmMinute = (alarm->AlarmMinute-1) % 60;
  4708.                     displayReminderTime( hWnd, EditItem );
  4709.                     return 0;
  4710.                     }
  4711.             //------------------------------------------------------------------
  4712.             //------------------------------------------------------------------
  4713.                 case HOUR_MORE: {
  4714.                     alarm->AlarmHour = (alarm->AlarmHour+1) % 24;
  4715.                     displayReminderTime( hWnd, EditItem );
  4716.                     return 0;
  4717.                     }
  4718.             //------------------------------------------------------------------
  4719.             //------------------------------------------------------------------
  4720.                 case HOUR_LESS: {
  4721.                     if (alarm->AlarmHour == 0)
  4722.                         alarm->AlarmHour = 23;
  4723.                     else
  4724.                         alarm->AlarmHour = (alarm->AlarmHour-1) % 24;
  4725.                     displayReminderTime( hWnd, EditItem );
  4726.                     return 0;
  4727.                     }
  4728.             //------------------------------------------------------------------
  4729.             //------------------------------------------------------------------
  4730.                 case DID_OK:  {
  4731.                     if (alarm->options & SCHEDULE_LAUNCHAPP)
  4732.                         alarm->options = SCHEDULE_LAUNCHAPP;
  4733.                     else {
  4734.                         alarm->options = 0;
  4735.                         WinQueryDlgItemText( hWnd, REMINDER,
  4736.                                              MAXACTIONSTRINGLENGTH,
  4737.                                              (PSZ)alarm->ActionToDo );
  4738.                         }
  4739.  
  4740.                 if (WinQueryButtonCheckstate( hWnd, EVERYHOUR ))
  4741.                     alarm->options += SCHEDULE_EVERYHOUR;
  4742.                 else if (WinQueryButtonCheckstate( hWnd, EVERYDAY ))
  4743.                     alarm->options += SCHEDULE_EVERYDAY;
  4744.                 else if (WinQueryButtonCheckstate( hWnd, EVERYWEEK ))
  4745.                     alarm->options += SCHEDULE_EVERYWEEK;
  4746.                 else if (WinQueryButtonCheckstate( hWnd, EVERYMONTH ))
  4747.                     alarm->options += SCHEDULE_EVERYMONTH;
  4748.                 else if (WinQueryButtonCheckstate( hWnd, EVERYYEAR ))
  4749.                     alarm->options += SCHEDULE_EVERYYEAR;
  4750.  
  4751.                 if (WinQueryButtonCheckstate( hWnd, PLAYSOUND ))
  4752.                     alarm->options += SCHEDULE_USEWAVFILE;
  4753.                 if (WinQueryButtonCheckstate( hWnd, SOUNDONLY ))
  4754.                     alarm->options += SCHEDULE_SOUNDONLY;
  4755.  
  4756.                 WinQueryDlgItemText( hWnd, SOUNDFILE,
  4757.                                      MAXACTIONSTRINGLENGTH,
  4758.                                      (PSZ)alarm->ReminderWAV );
  4759.  
  4760.                 WinDismissDlg( hWnd, TRUE );
  4761.                 return 0;
  4762.                 }
  4763.                 default:
  4764.                     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4765.             }
  4766.         }
  4767.         //----------------------------------------------------------------------
  4768.         // if nothing further we want to intercept, pass message onto system
  4769.         //----------------------------------------------------------------------
  4770.         default:
  4771.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4772.  
  4773.     }
  4774. }
  4775.  
  4776.  
  4777. ////////////////////////////////////////////////////////////////////////////////
  4778. ////////////////////////////////////////////////////////////////////////////////
  4779. MRESULT EXPENTRY reminderNoteProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  4780. {
  4781.    switch( msg )
  4782.     {
  4783.         //----------------------------------------------------------------------
  4784.         //----------------------------------------------------------------------
  4785.         case WM_TIMER: {
  4786.             ringChime( currentReminderWavFile );
  4787.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4788.             }
  4789.         //----------------------------------------------------------------------
  4790.         // when the dialog is being initialized, center it on desktop
  4791.         //----------------------------------------------------------------------
  4792.         case WM_INITDLG: {
  4793.             SWP swp;
  4794.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  4795.             WinSetWindowPos( hWnd, (HWND)0,
  4796.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  4797.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  4798.                              0, 0, SWP_MOVE);
  4799.             noteTimerNumber = WinStartTimer( hab, hWnd, TIMERID+1, (LONG)repeatTime*1000 );
  4800.             numberOfAlarms = numAlarms;
  4801.             numAlarms = 0;
  4802.             if (mp2 != 0)
  4803.                 WinSetDlgItemText( hWnd, REMINDER, (CHAR*)LONGFROMMP( mp2 ) );
  4804.             WinPostMsg( hWnd, WM_TIMER, mp1, mp2 );
  4805.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4806.             }
  4807.         //----------------------------------------------------------------------
  4808.         // if we receive any system message, dismiss the dialog box
  4809.         //----------------------------------------------------------------------
  4810.         case WM_COMMAND:
  4811.         {
  4812.             USHORT command = SHORT1FROMMP(mp1);
  4813.  
  4814.             switch(command) {
  4815.             //------------------------------------------------------------------
  4816.             //------------------------------------------------------------------
  4817.             case DID_OK: {
  4818.                 WinStopTimer( hab, TIMERID+1, noteTimerNumber );
  4819.                 WinDismissDlg( hWnd, TRUE );
  4820.                 numAlarms = numberOfAlarms;
  4821.                 oldItemName[0] = FALSE;
  4822.                 return 0;
  4823.                 }
  4824.             //------------------------------------------------------------------
  4825.             //------------------------------------------------------------------
  4826.             case SNOOZE: {
  4827.                 ALARMS* alarm = alarmPtr[0];
  4828.                 struct tm *time_now;
  4829.                 time_t currentTime;
  4830.  
  4831.                 WinStopTimer( hab, TIMERID+1, noteTimerNumber );
  4832.  
  4833.                 tzset();
  4834.                 time(¤tTime);
  4835.                 time_now = localtime( ¤tTime );
  4836.                 alarm->AlarmDay = time_now->tm_mday-1;
  4837.                 alarm->AlarmMonth = time_now->tm_mon;
  4838.                 alarm->AlarmYear = time_now->tm_year;
  4839.                 alarm->AlarmHour = time_now->tm_hour;
  4840.                 alarm->AlarmMinute = time_now->tm_min + 9;
  4841.  
  4842.                 validateTimeEntry();
  4843.                 sortTimeEntries( numberOfAlarms );
  4844.                 WinDismissDlg( hWnd, TRUE );
  4845.                 numAlarms = numberOfAlarms;
  4846.                 return 0;
  4847.                 }
  4848.             //------------------------------------------------------------------
  4849.             //------------------------------------------------------------------
  4850.             case REVISE: {
  4851.                 WinStopTimer( hab, TIMERID+1, noteTimerNumber );
  4852.                 reviseScheduledItem( 0 );
  4853.                 validateTimeEntry();
  4854.                 sortTimeEntries( numberOfAlarms );
  4855.                 WinDismissDlg( hWnd, TRUE );
  4856.                 numAlarms = numberOfAlarms;
  4857.                 return 0;
  4858.                 }
  4859.             //------------------------------------------------------------------
  4860.             //------------------------------------------------------------------
  4861.             case ERASE: {
  4862.                 WinStopTimer( hab, TIMERID+1, noteTimerNumber );
  4863.                 if (WinMessageBox( HWND_DESKTOP, hwndFrame,
  4864.                                    "Are you sure you want to completely erase this reminder?",
  4865.                                    "Erase this reminder", 0,
  4866.                                    MB_MOVEABLE|MB_ICONQUESTION|MB_YESNO)==MBID_YES) {
  4867.                     delete alarmPtr[ 0 ];
  4868.                     for (short i=1; i<MAXALARMS; i++)
  4869.                         alarmPtr[ i-1 ] = alarmPtr[ i ];
  4870.                     WinDismissDlg( hWnd, TRUE );
  4871.                     numAlarms = numberOfAlarms-1;
  4872.                     }
  4873.                 noteTimerNumber = WinStartTimer( hab, hWnd, TIMERID+1, (LONG)repeatTime*1000 );
  4874.                 return 0;
  4875.                 }
  4876.             //------------------------------------------------------------------
  4877.             //------------------------------------------------------------------
  4878.             default:
  4879.                 return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4880.             }
  4881.         }
  4882.         //----------------------------------------------------------------------
  4883.         // if nothing further we want to intercept, pass message onto system
  4884.         //----------------------------------------------------------------------
  4885.         default:
  4886.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4887.     }
  4888. }
  4889.  
  4890.  
  4891. ////////////////////////////////////////////////////////////////////////////////
  4892. ////////////////////////////////////////////////////////////////////////////////
  4893. MRESULT EXPENTRY LaunchItemProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  4894. {
  4895.    ALARMS* alarm = alarmPtr[EditItem];
  4896.  
  4897.    switch( msg )
  4898.     {
  4899.         //----------------------------------------------------------------------
  4900.         // when the dialog is being initialized, center it on desktop
  4901.         //----------------------------------------------------------------------
  4902.         case WM_INITDLG: {
  4903.             SHORT i,j;
  4904.             CHAR temp[MAXACTIONSTRINGLENGTH+5];
  4905.             SWP swp;
  4906.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  4907.             WinSetWindowPos( hWnd, (HWND)0,
  4908.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  4909.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  4910.                              0, 0, SWP_MOVE);
  4911.  
  4912.             oldAction[LAUNCHED] = alarm->options & SCHEDULE_LAUNCHAPP;
  4913.             WinSendDlgItemMsg( hWnd, CURITEMLIST, LM_DELETEALL, 0, 0);
  4914.             temp[0] = ' ';
  4915.             temp[1] = ' ';
  4916.             temp[2] = '-';
  4917.             temp[3] = ' ';
  4918.             for (i=0; i<NumMenus; i++) {
  4919.                 WinSendDlgItemMsg( hWnd, CURITEMLIST, LM_INSERTITEM, MPFROMSHORT( LIT_END ), MenuName[i] );
  4920.                 for (j=0; j<NumItems[i]; j++)
  4921.                    if (Menus[i][j]->ItemName[0] != '\0') {
  4922.                         temp[4] = '\0';
  4923.                         strcat(temp, Menus[i][j]->ItemName);
  4924.                         WinSendDlgItemMsg( hWnd, CURITEMLIST, LM_INSERTITEM, MPFROMSHORT( LIT_END ), temp );
  4925.                         }
  4926.                 }
  4927.  
  4928.             // if they had requested to launch an application previously
  4929.             // restore their choice in the dialog box
  4930.             WinCheckButton( hWnd, LAUNCHITEM, FALSE );
  4931.             if (oldAction[LAUNCHED]) {
  4932.                 SHORT item, index;
  4933.                 WinCheckButton( hWnd, LAUNCHITEM, TRUE );
  4934.  
  4935.                 item = 0;
  4936.                 index = alarm->ActionToDo[0];
  4937.                 if (index > 0) {
  4938.                     for (i=0; i<index; i++) {
  4939.                         item++;
  4940.                         for (j=0; j<NumItems[i]; j++)
  4941.                             if (Menus[i][j]->ItemName[0] != '\0')
  4942.                                 item++;
  4943.                         }
  4944.                     }
  4945.  
  4946.                 item += alarm->ActionToDo[1]+1;
  4947.  
  4948.                 for (j=0; j<alarm->ActionToDo[1]; j++)
  4949.                     if (Menus[index][j]->ItemName[0] == '\0')
  4950.                         item--;
  4951.  
  4952.                 WinSendDlgItemMsg( hWnd, CURITEMLIST, LM_SELECTITEM,
  4953.                                    MPFROM2SHORT( item, 0 ),
  4954.                                    MPFROM2SHORT( TRUE, 0 ) );
  4955.                 }
  4956.  
  4957.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4958.             }
  4959.         //----------------------------------------------------------------------
  4960.         //----------------------------------------------------------------------
  4961.         case WM_CONTROL:
  4962.         {
  4963.             if (SHORT1FROMMP(mp1)==CURITEMLIST) {
  4964.                 if (SHORT2FROMMP(mp1)==LN_ENTER) {
  4965.                     WinCheckButton( hWnd, LAUNCHITEM, TRUE );
  4966.                     WinSendMsg( hWnd, WM_COMMAND, MPFROMSHORT(DID_OK), 0 );
  4967.                     }
  4968.                 if (SHORT2FROMMP(mp1)==LN_SELECT)
  4969.                     WinCheckButton( hWnd, LAUNCHITEM, TRUE );
  4970.                 }
  4971.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4972.         }
  4973.         //----------------------------------------------------------------------
  4974.         //----------------------------------------------------------------------
  4975.         case WM_COMMAND:
  4976.         {
  4977.             if (SHORT1FROMMP(mp1)==DID_OK) {
  4978.                 SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURITEMLIST,
  4979.                                                                       LM_QUERYSELECTION,
  4980.                                                                       MPFROM2SHORT( LIT_FIRST, 0 ),
  4981.                                                                       0 ) );
  4982.                 if (WinQueryButtonCheckstate( hWnd, LAUNCHITEM )) {
  4983.                         short i,j;
  4984.                         char temp[MAXPATH];
  4985.  
  4986.                         WinSendDlgItemMsg( hWnd, CURITEMLIST,
  4987.                                                LM_QUERYITEMTEXT,
  4988.                                                MPFROM2SHORT( itemSelected, sizeof(temp) ),
  4989.                                                (PSZ)temp );
  4990.  
  4991.                         if (strncmp(temp, "  - ", 4) != 0) {
  4992.                             WinMessageBox( HWND_DESKTOP, hwndFrame,
  4993.                                            "You must select an item (NOT a menu) from the list!",
  4994.                                            "Task Scheduler: Launch an Application", 0,
  4995.                                            MB_MOVEABLE|MB_ERROR|MB_OK);
  4996.                             return 0;
  4997.                             }
  4998.  
  4999.                         if ( !oldAction[LAUNCHED] )
  5000.                             alarm->options += SCHEDULE_LAUNCHAPP;
  5001.  
  5002.                         for (i=0; i<NumMenus; i++)
  5003.                             for (j=0; j<NumItems[i]; j++)
  5004.                                 if (strcmp( temp+4, Menus[i][j]->ItemName ) == 0) {
  5005.                                     alarm->ActionToDo[0] = i;
  5006.                                     alarm->ActionToDo[1] = j;
  5007.                                     }
  5008.                     }
  5009.                 else {
  5010.                     if ( oldAction[LAUNCHED] ) {
  5011.                         alarm->options -= SCHEDULE_LAUNCHAPP;
  5012.                         alarm->ActionToDo[0] = 0;
  5013.                         }
  5014.                     }
  5015.                 WinDismissDlg( hWnd, TRUE );
  5016.                 return 0;
  5017.                 }
  5018.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5019.         }
  5020.         //----------------------------------------------------------------------
  5021.         // if nothing further we want to intercept, pass message onto system
  5022.         //----------------------------------------------------------------------
  5023.         default:
  5024.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5025.     }
  5026. }
  5027.  
  5028.  
  5029. ////////////////////////////////////////////////////////////////////////////////
  5030. ////////////////////////////////////////////////////////////////////////////////
  5031. MRESULT EXPENTRY popUpOptionsProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  5032. {
  5033.    switch( msg )
  5034.     {
  5035.         //----------------------------------------------------------------------
  5036.         // when the dialog is being initialized, center it on desktop
  5037.         //----------------------------------------------------------------------
  5038.         case WM_INITDLG: {
  5039.             SWP swp;
  5040.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  5041.             WinSetWindowPos( hWnd, (HWND)0,
  5042.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  5043.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  5044.                              0, 0, SWP_MOVE);
  5045.             WinCheckButton( hWnd, MOUSE_CHORD, (popUpMessageID==WM_CHORD) );
  5046.             WinCheckButton( hWnd, MOUSE_BUT3, (popUpMessageID==WM_BUTTON3CLICK) );
  5047.             WinCheckButton( hWnd, HIDE_FILEBAR, (hideFileBar==TRUE) );
  5048.             WinCheckButton( hWnd, ENABLE_POPUP, (allowPopUpMenu==TRUE) );
  5049.             WinEnableControl( hWnd, REMINDER, FALSE );
  5050.  
  5051.             if (WinQueryButtonCheckstate( hWnd, HIDE_FILEBAR ))
  5052.                 WinEnableControl( hWnd, ENABLE_POPUP, FALSE );
  5053.             else
  5054.                 WinEnableControl( hWnd, ENABLE_POPUP, TRUE );
  5055.  
  5056.             if (WinQueryButtonCheckstate( hWnd, ENABLE_POPUP ))
  5057.                 WinEnableControl( hWnd, HIDE_FILEBAR, TRUE );
  5058.             else
  5059.                 WinEnableControl( hWnd, HIDE_FILEBAR, FALSE );
  5060.  
  5061.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5062.             }
  5063.         //----------------------------------------------------------------------
  5064.         // if we receive any system message, dismiss the dialog box
  5065.         //----------------------------------------------------------------------
  5066.         case WM_CONTROL:
  5067.         {
  5068.             if (WinQueryButtonCheckstate( hWnd, HIDE_FILEBAR ))
  5069.                 WinEnableControl( hWnd, ENABLE_POPUP, FALSE );
  5070.             else
  5071.                 WinEnableControl( hWnd, ENABLE_POPUP, TRUE );
  5072.  
  5073.             if (WinQueryButtonCheckstate( hWnd, ENABLE_POPUP ))
  5074.                 WinEnableControl( hWnd, HIDE_FILEBAR, TRUE );
  5075.             else
  5076.                 WinEnableControl( hWnd, HIDE_FILEBAR, FALSE );
  5077.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5078.         }
  5079.  
  5080.         //----------------------------------------------------------------------
  5081.         // if we receive any system message, dismiss the dialog box
  5082.         //----------------------------------------------------------------------
  5083.         case WM_COMMAND:
  5084.         {
  5085.             if (WinQueryButtonCheckstate( hWnd, MOUSE_CHORD ))
  5086.                 popUpMessageID = WM_CHORD;
  5087.             if (WinQueryButtonCheckstate( hWnd, MOUSE_BUT3 ))
  5088.                 popUpMessageID = WM_BUTTON3CLICK;
  5089.             hideFileBar = WinQueryButtonCheckstate( hWnd, HIDE_FILEBAR );
  5090.             allowPopUpMenu = WinQueryButtonCheckstate( hWnd, ENABLE_POPUP );
  5091.             setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  5092.                               allowPopUpMenu, popUpMessageID );
  5093.             if (hideFileBar)
  5094.                 WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0, SWP_HIDE);
  5095.             else
  5096.                 WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0, SWP_SHOW);
  5097.             WinDismissDlg( hWnd, TRUE );
  5098.             return 0;
  5099.         }
  5100.         //----------------------------------------------------------------------
  5101.         // if nothing further we want to intercept, pass message onto system
  5102.         //----------------------------------------------------------------------
  5103.         default:
  5104.             break;
  5105.     }
  5106.     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5107. }
  5108.  
  5109.  
  5110.  
  5111.